Sonoff + tasmota firmware + http binding

here is an easier way of connecting your Sonoff tasmota flashed devices to openhab2 (havent tried it with orginal firmware)

install the http binding

Items.items
Switch Sonoff       "Sonoff"        { http=">[ON:POST:http://192.168.1.169/cm?user=admin&password=urpassgoeshere&cmnd=Power%%20ON] >[OFF:POST:http://192.168.1.169/cm?user=admin&password=urpassgoeshere&cmnd=Power%%20OFF]" }                                    



the actual http command is 
http://192.168.1.169/cm?user=admin&password=urpassgoeshere&cmnd=Power%20ON
i had to add an extra % for it to work cause the % calls for an action and %% to ignore
took me some time to figure this out



sitemap.sitemap
Switch item=Sonoff		mappings=[ON="ON", OFF="OFF"]

havent played around with the JSON command to read the state yet

5 Likes

@alokin79 Thank you, it actually took me finding your post to figure out how to escape the spaces. Have you been able to integrate active status polling from the switch? I can display it OK but my openHab interface doesn’t update accordingly, only on manual refresh.

Cheers
goddib

Thank you, @alokin79,

the hint with two "%% " has helped me finally getting the sonof tasmotas to work!

Welcome to the openHAB Forum!

Why don’t you try to connect the sonoff using the MQTT protocol? That is more commonly used.

String SonoffGardenaGV     "Sonoff GetValue"    { http="<[http://192.168.1.138/cm?user=root&password=pass&cmnd=Power:60000:REGEX(.*?\\{\"POWER\":\"(.*?)\"\\}.*)]"}
Text item=SonoffGardenaGV 		icon="auto"			label="Status [%s]"

im on OpenHAB 2.2

I actually got it to work like this in the end (requires JSONPATH)

Switch rfplug2 "Office Light [%s]" { http=">[ON:GET:http://192.168.178.58/cm?cmnd=Power%%20On] >[OFF:GET:http://192.168.178.58/cm?cmnd=Power%%20Off] <[http://192.168.178.58/cm?cmnd=Power:30000:JSONPATH($.POWER)]" }

In the sitemap I simply include the Switch with no further formating.

@opus Every new binding requires hours of research. At the moment I’m struggling to get homegear/homematic binding to work so I prefer to keep the rest as simple as possible. From my understanding MQTT would require a separate server to connect?

Yes, a MQTT server is needed. I have one running besides openHAB on my raspi3.

Please how should be inserted %% or @@ characters on Sonoff POW2 switch (espurna firmware)?
On bash command executes OK.
How should be propperly substitued with %% or @@ characters in rules ?

Terminal window:
curl -X PUT -H “Accept: application/json” http://localip/api/relay/0 --data “apikey=xxxxxxxxxxx&value=1”

Also working on restfull api off:
curl -X GET "http://localip/api/relay/0?apikey=xxxxxxxxxxxxxxx&value=1

Rules:
executeCommandLine("curl -X PUT -H “Accept: application/json” http://localip/api/relay/0 --data “apikey=xxxxxxxxxxx&value=1"”)