Are you wanting to subscribe (inwards) or publish (outwards)?
It’s often better to explain what you want to do rather than half code a possible solution
It looks like if the relay gets an update (either on or off) you want to do something else but it’s not clear.
So if you state what the condition is that you want to respond to and then you say what you want to happen we can help you better. We often try to help then find out a better solution is something completely different because we don’t have all the facts.
Regards
Phil K
Sent from Mail for Windows 10
--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/sonoffusers/f053ac95-a7a4-4bac-b6e0-464875399bc2n%40googlegroups.com.
That’s OK if in doubt write it in French (I presume) and we can use Google translate to try to make sense of it.
Tasmota already publishes the relay state via MQTT when the state changes.
stat/Sonoff-Pump/RESULT={"POWER":"OFF"}
or
stat/Sonoff-Pump/POWER=”OFF”
plus in the regular updates at TelePeriod
tele/Sonoff-Pump/STATE={"Time":"2021-05-10T10:23:28","Uptime":"17T04:02:54","UptimeSec":1483374,"Heap":23,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"MqttCount":18,"POWER":"OFF","Wifi":{"AP":1,"SSId":"pkm-24m","BSSId":"38:6B:1C:40:3D:D9","Channel":9,"RSSI":80,"Signal":-60,"LinkCount":13,"Downtime":"0T00:00:29"}}
Most control system will directly accept the stat/x/POWER message but in some cases you may need to use a JSONPATH transformation to extract the data
Don’t know if that helps.
To view this discussion on the web, visit https://groups.google.com/d/msgid/sonoffusers/fabe5aa3-3c26-4ca9-b037-0af9079e4a01n%40googlegroups.com.
It’s explained here but you need to compile you own binary
Subscribe & Unsubscribe - Tasmota
You may be better using something like Node-Red to read the MQTT messages and then command the relay on the Sonoff.
To view this discussion on the web, visit https://groups.google.com/d/msgid/sonoffusers/fb2ce698-89c5-4cf0-bff0-58f61bd53131n%40googlegroups.com.
Hello,
If you have own server with MQTT or some shell script, can run like I use on my OpenWrt Router:
#!/bin/sh
....
function publish()
{
mosquitto_pub -t "$1" -m "$2"
}
...
while true; do
mosquitto_sub -v -t 'door/#' -t '+/+/LWT' -q 0 | \
while read msg; do
t=$(echo $msg|awk '{print $1}')
v=$(echo $msg|awk '{print $2}')
#echo "readed: $msg. $t:$v"
case "$t" in
"door/opened")
publish "cmnd/led_01/power0" "off"
;;
....
esac
done
sleep 5
echo "restat loop"
done
And then can publish to tasmota with w/o recompile custom
firmware.
To view this discussion on the web, visit https://groups.google.com/d/msgid/sonoffusers/fb2ce698-89c5-4cf0-bff0-58f61bd53131n%40googlegroups.com.