tasmota mqtt & json

284 views
Skip to first unread message

Dominique Malissen

unread,
May 10, 2021, 4:38:45 AM5/10/21
to TasmotaUsers
hello , newbie with tasmota ,
is it possible to , with recpept server mqtt ( mosquito ) , to do "on - off " relay if "RELAIS" = 1 or 0 ?
the json subscribe " sdb_statut" mqtt server 192.168.1.51 -> {'relais': {'CLIM': 0, 'RELAIS': 0, 'LED': 0}, 'mode': 'Travail', 'temperature': 22.03, 'consigne': 18.0

thank you

if possible can you help please

Philip Knowles

unread,
May 10, 2021, 5:01:54 AM5/10/21
to Dominique Malissen, TasmotaUsers

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.

 

bledad

unread,
May 10, 2021, 5:13:33 AM5/10/21
to TasmotaUsers
hello , sorry i no understand , my english it's verry bad .
i have a sonoff with tasmota installed , I would like to recover of my mqtt server the " RELAIS "value
with this value , on my sonoff , if value = 1 , the relay of sonoff is on else off
Rdgs

Philip Knowles

unread,
May 10, 2021, 5:30:28 AM5/10/21
to bledad, TasmotaUsers

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.

 

Regards

 

Phil K

Sent from Mail for Windows 10

 

bledad

unread,
May 10, 2021, 8:38:23 AM5/10/21
to TasmotaUsers
i no want publish  , i want , with sonoff , client subscribe
little drawing
tasmotat.jpg

Philip Knowles

unread,
May 10, 2021, 10:18:54 AM5/10/21
to bledad, TasmotaUsers

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.

lexxai

unread,
May 10, 2021, 3:58:09 PM5/10/21
to sonof...@googlegroups.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.



10.05.21 15:38, bledad :
Reply all
Reply to author
Forward
0 new messages