[SOLVED] Sonoff POW2 espurna FW reflashed, items for U,I,P,Q,cosfi,energy via http bindig

values from http api request are shown in internet browser via http requests:

Is this item definition possible ?

String Pow2_Voltage “Pow2 [%s]” (Sonoff) { http="<[http://sonoffpow2ip/api/voltage?apikey=xxxxxxxxxxxxxxxx]" }
Answer is 223 (meanings Volt)


How shoulde be defined items for this Numbers ? Strings ? vaules ?

If the result of the transform is just a number with no units or extra spaces then you can use a Number. Otherwise you need to use a String or parse it there non number parts using a Rule.

Hello Rich. Thanks for answer.
It looks like string without anything.

String Pow2_Voltage “Pow2 [%s]” (Sonoff) { http="<[http://pow2ip/api/voltage?apikey=xxxxxxxx]" }
gives no value back to string item.

Perhaps, but as as far as one can tell in that screenshot there could be a space before or after the 230 or there could be some HTML tags which would be hidden in the browser.

Do you see errors in the log?

Small python script returns the value:

import requests

r = requests.get(‘http://pow2ip/api/voltage?apikey=xxxxxxxxxxxxxxxx’)
data = r.content

(‘Voltage=’, ‘231’, ‘V’)

How should i put the 232 value to a string item and convert it to number.
Number would be used in rules for comparissons.

Have you installed the HTTP binding?

Yes of course

this returns string
String Pow2_Voltage “Pow2 Voltage [%s V]” (Sonoff) { http="<[http://sonoffip/api/voltage?apikey=xxxxxxxxxxxxxxxxx:3000:JSONPATH($.data)]" }

For display it is enough. But I need to make some rules for comparison of number values.
If Pow2_Power is greater as high trigger value = daikin is on, if Pow2_Power is below low trigger value= daikin is off.

How to convert string value to number please ?
Can it be done with REGEX g´transformation or converting rule should be created ?

Like I said above, if what JSONPATH($.data) is just a number with no spaces or non-number characters then just change the Item type to Number.

Number Pow2_Voltage ...

If not, you will need a Rule that triggers when Pow2_Voltage changes, strips off the extraneous characters using String.split or a regex transform and updates the value of the Number Pow2_Voltage_Proxy Item.

Item Number definition works fine, thanks for help Rich.

My sollution also with MQTT

// Sonoff via MQTT
Group  Sonoff_POW

Switch Sonoff_POW_Switch    "Power switch"         <energy> (Sonoff_POW) { channel="mqtt:topic:mosquitto:sonoffpow2:relay/0" }
Number Sonoff_POW_Load      "Power load [%.1f W]"  <energy> (Sonoff_POW) { channel="mqtt:topic:mosquitto:sonoffpow2:power" }
Number Sonoff_POW_Voltage   "Voltage [%.1f V]"     <energy> (Sonoff_POW) { channel="mqtt:topic:mosquitto:sonoffpow2:voltage" }
Number Sonoff_POW_Current   "Current [%.3f A]"     <energy> (Sonoff_POW) { channel="mqtt:topic:mosquitto:sonoffpow2:current" }
Number Sonoff_POW_Apparent  "Apparent [%.0f VAr]"  <energy> (Sonoff_POW) { channel="mqtt:topic:mosquitto:sonoffpow2:apparent" }
Number Sonoff_POW_Energy    "Energy [%.3f kWh]"    <energy> (Sonoff_POW) { channel="mqtt:topic:mosquitto:sonoffpow2:energy" }
Number Sonoff_POW_Factor    "Factor [%.0f]"        <energy> (Sonoff_POW) { channel="mqtt:topic:mosquitto:sonoffpow2:factor" }


Bridge mqtt:broker:mosquitto "embedded-mqtt-broker" [ host="RPi_IP", port=1883, secure=false, username="", password="" ]
    Thing topic sonoffpow2  {
        Type switch : switch       "Power relay"     [ stateTopic="ESPURNA-CA45ED/data", commandTopic="ESPURNA-CA45ED/relay/0/set", transformationPattern="JSONPATH:$.relay/0"  ]
        Type number : voltage      "Line voltage"    [ stateTopic="ESPURNA-CA45ED/data", transformationPattern="JSONPATH:$.voltage"]
        Type number : power        "Power load"      [ stateTopic="ESPURNA-CA45ED/data", transformationPattern="JSONPATH:$.power"]
        Type number : apparent     "Power apparent"  [ stateTopic="ESPURNA-CA45ED/data", transformationPattern="JSONPATH:$.apparent"]
        Type number : current      "Line current"    [ stateTopic="ESPURNA-CA45ED/data", transformationPattern="JSONPATH:$.current"]
        Type number : factor       "Line factor"     [ stateTopic="ESPURNA-CA45ED/data", transformationPattern="JSONPATH:$.factor"]        
        Type number : energy       "Energy today"    [ stateTopic="ESPURNA-CA45ED/data", transformationPattern="JSONPATH:$.energy"]


 Group  item=Sonoff_POW