[SOLVED] String from HTTP sentence Sonoff


(Juan) #1

Hi there,

Is it possible to get a string from the http in order to get the following info?

Something like:

String Raw {http="http://192.168.2.135/cm?cmnd=STATUS"}

I do not get that it works…


(Harry) #2

Have you worked with refreshintervalinmilliseconds or Command?


What value does the item have?


(Vincent Regaud) #3
val String response = sendHttpGetRequest("http://192.168.2.135/cm?cmnd=STATUS")

But this is from a Sononf with tasmota firmware.
Have you heard of MQTT?


(Juan) #4

Yes, I know.
But I would like to get the POWER from http.

I want to pass this string:

{"POWER":"OFF"}

I have this rule:

rule "Power Rele"
when Item sonoff06 changed to ON
then
String estado "estado" { http="<[http://192.168.2.135/cm?cmnd=status/power]" }
logInfo("rule","Estado " + estado)
end

(Juan) #5

OK, it works.

Now I want to extract the field Power as a Number… to work with other rules

2018-07-12 15:22:11.613 [INFO ] [.eclipse.smarthome.model.script.rule] - Estado {"Status":{"Module":1,"FriendlyName":["Sonoff06"],"Topic":"sonoff06","ButtonTopic":"0","Power":1,"PowerOnState":3,"LedState":1,"SaveData":1,"SaveState":1,"ButtonRetain":0,"PowerRetain":0}}

(Vincent Regaud) #6
val String sonoffStatus = transform("JSONPATH", "$.POWER", response }

(Juan) #7

Thank you!!!