MQTT with python

You can’t have them both subscribing/publishing using the same deviceID to Losant.

Thats why I am saying don’t connect nodered to Losant (unless you have another reason too)
and send the data directly from Python code -> Losant and Node red at the same time.

If you want Node Red to also communicate with Losant create a different device for it.

Then you can have losant send data received from the PI -> Nodered via a device command node in a Losant workflow which Node red can subscribe too.

As a test, on the PI, within nodered itself, I did run sending message via mqtt and also subscribed to it. There was no disconnects seen. I do not get it why it does not work the way I am trying to do - on the PI, sending via a python code and scubscribing in node red

Two different physical connections to the same device. It isn’t allowed. Thats a Losant architectural feature. You might work around it by using gateways and peripherals or node-red use the REST api.

But to be honest I don’t see why you want to approach it in this manner.

And if you really do want this topology you can get around this by setting up Mosquitto bridge on the PI, and have the Python code (not Losant-python but simple paho lib) and node-red subscribe / publish to the local mosquitto instance and let mosquitto forward to losant.