@tbowmo Thanks @tbowmo and everybody! This active community has really saved my day so many times. You rule guys and gals!
Here is a working script:
import paho.mqtt.client as mqttClient
import sys
irCommand = sys.argv[1]
print("Parameter is: " + irCommand)
client = mqttClient.Client("Python")
client.username_pw_set(username="xxx",password="xxx")
client.connect("nnn.nnn.nnn.nnn", 1883)
client.publish('domoticz/out/HomeNum_IR/0/0/1/0/47', irCommand, retain=False)
# (ESP8266 "gateway" MQTT client -> node=0)
And call it from Domoticz virtual selector switch:
script:///home/pi/domoticz/scripts/python/hnumber_led_mode.py 7
Parameter is the desired mode for led animation. Made a similar on for IR remote commands.
Is there same ~25bit payload limit with MQTT too? I mean those NEC IR commands tend to be 32bit so probably cannot send them directly but need to be hardcoded in the sketch? Also planned to create a universal script for these needs where you could give also node number, child ids etc but then again...I chain myself even tighter to Domoticz shackles and again Domoticz should support this without scripting.
Couple of more questions:
- If you have several ESP8266 MQTT gateways, should one create a different topic for everyone or put them in the same MySensors queue? If so, will the MY_MQTT_CLIENT_ID make the separation?
- I installed nodered-contrib-mysensors and it seems very promising. Definitely going to play around with it. I probably still need some actual controller but Node-red seems to be important part whatever you're gonna do especially when using MQTT queues.
- When using MQTT instead of Ethernet GW, I lose small but very important check: node pinging. I can see from Domoticz log warning messages when some of my ESP8266 Ethernet nodes are down, but when using MQTT there are no warnings, just no data received. I assume this is quite logical because the MQTT node's address in Domoticz is actually broker's (Mosquitto) address + right MQTT topic. However, when sniffing Domoticz MQTT traffic, it seems to send PING messages quite regularly (but don't know if this triggers anything if the ping success or fails...):
// MQTT topic: domoticz/out/HomeNum_IR/#
PING
qos : 0, retain : false, cmd : publish, dup : false, topic : domoticz/out/HomeNum_IR/0/0/3/0/18, messageId : , length : 40
Update: Seems that the Domo has it's own requirements for MQTT queues and for preventing overlapping ESP8266 = GW = Node ID 0 have an option to have also Node ID in the MQTT queue definition. Still would be nice to be able to define the MQTT queue names freely in Domo...
Also my bad: MySensors payload size is 25 bytes, not bits... This seems to be because of NFR24L01 limitations. However, it would be nice to see an extended payload size for passing eg. longer text information with more advanced microcontrollers like ESP8266 in the future releases. Minor need though.