So with the help I got here I got it all working. My goal is to have controls on my HASP plate (touch screen that replaces wall switched).
I needed the pod state to mainly be stored in the sensibo api so I changed the code a little. Instead of posting changes I will just post the files It updates every 5 min but I will change it to update when I change to that page on the touchscreen.
sitemap sensibo label="Sensibo" {
Frame label="Sensibo Living" {
Switch item=Sensibo_Living_State label="Sensibo_Living_State" mappings=["true"="ON", "false"="OFF"] icon="switch"
Switch item=Sensibo_Living_Mode label="Mode" icon="heating" mappings=[cool="Cool",heat="Heat",fan="Fan"]
Setpoint item=Sensibo_Living_Target label="Target [%.0f ºC]" icon="temperature" minValue=18 maxValue=26 step=1.0
Switch item=Sensibo_Living_Fan label="Fan" icon="fan" mappings=[low="Low",medium="Med",high="High",auto="Auto"]
Switch item=Sensibo_Living_Swing label="Swing" icon="fan" mappings=[stopped="Stop",fixedMiddle="Middle",fixedTop="High",rangeFull="Swing"]
Text item=Sensibo_Living_Temp label="Temperature [%.1f ºC]" icon="temperature"
Text item=Sensibo_Living_Humidity label="Humidity [%.0f %%]" icon="water"
// Text item=Sensibo_Living_Battery label="Battery [%d mV]" icon="energy"
}
Frame label="Sensibo Bedroom" {
Switch item=Sensibo_Bedroom_State label="Sensibo Bedroom State" mappings=["true"="ON", "false"="OFF"] icon="switch"
Switch item=Sensibo_Bedroom_Mode label="Mode" icon="heating" mappings=[cool="Cool",heat="Heat",fan="Fan"]
Setpoint item=Sensibo_Bedroom_Target label="Target [%.0f ºC]" icon="temperature" minValue=18 maxValue=26 step=1.0
Switch item=Sensibo_Bedroom_Fan label="Fan" icon="fan" mappings=[low="Low",medium="Med",high="High",auto="Auto"]
Switch item=Sensibo_Bedroom_Swing label="Swing" icon="fan" mappings=[stopped="Stop",fixedMiddle="Middle",fixedTop="High",rangeFull="Swing"]
Text item=Sensibo_Bedroom_Temp label="Temperature [%.1f ºC]" icon="temperature"
Text item=Sensibo_Bedroom_Humidity label="Humidity [%.0f %%]" icon="water"
// Text item=Sensibo_Bedroom_Battery label="Battery [%d mV]" icon="energy"
}
}
Items
String Sensibo_Living_State
Number Sensibo_Living_Temp
Number Sensibo_Living_Humidity
Number Sensibo_Living_Battery
Number Sensibo_Living_Target
String Sensibo_Living_Fan
String Sensibo_Living_Mode
String Sensibo_Living_Swing
String Sensibo_Bedroom_State
Number Sensibo_Bedroom_Temp
Number Sensibo_Bedroom_Humidity
Number Sensibo_Bedroom_Battery
Number Sensibo_Bedroom_Target
String Sensibo_Bedroom_Fan
String Sensibo_Bedroom_Mode
String Sensibo_Bedroom_Swing
Rules
You need to enter your own apikey and podid
/*** openHAB Sensibo Rules ***/
// Goto the website https://home.sensibo.com/me/api first and create APIKey
val String APIKey = ""
var PodID_01 = "" //Living
var PodID_02 = "" //Bedroom
rule "Read Sensibo State PodID_01"
when
System started or
Time cron "0 0/5 * * * ?" //Update states from senibo every 5 min
then
//Thread::sleep(1000)
try {
var String PodStatus
do {
Thread::sleep(5000)
PodStatus = executeCommandLine('curl -sSH "Accept: application/json" "https://home.sensibo.com/api/v2/pods/' + PodID_01 + '/acStates?apiKey=' + APIKey + '&limit=1&fields=acState"', 5000)
//logInfo("Sensibo result - PodStatus", PodStatus)
} while (!PodStatus.contains('"status": "success"'))
val String PodOn = (transform("JSONPATH", "$.result[0].acState.on", PodStatus))
val String PodMode = (transform("JSONPATH", "$.result[0].acState.mode", PodStatus))
val Number PodTarget = new Integer(transform("JSONPATH", "$.result[0].acState.targetTemperature", PodStatus))
val String PodFan = (transform("JSONPATH", "$.result[0].acState.fanLevel", PodStatus))
postUpdate(Sensibo_Living_State, PodOn)
postUpdate(Sensibo_Living_Target, PodTarget)
postUpdate(Sensibo_Living_Mode, PodMode)
postUpdate(Sensibo_Living_Fan, PodFan)
if (PodStatus.contains('"swing": ')) {
val String PodSwing = (transform("JSONPATH", "$.result[0].acState.swing", PodStatus))
postUpdate(Sensibo_Living_Swing, PodSwing)
}
}
catch(Throwable t) {
logError("Sensibo read state", "Error was caught: {}", t)
}
end
rule "Read Sensibo Measurements PodID_01"
when
Time cron "0 0/5 * * * ?" //Update states from senibo every 5 min
then
try {
var String PodMeasurements
do {
PodMeasurements = executeCommandLine('curl -sSH "Accept: application/json" "https://home.sensibo.com/api/v2/pods/' + PodID_01 + '/measurements?apiKey=' + APIKey + '&fields=temperature,humidity,batteryVoltage"', 5000)
//logInfo("Sensibo result - PodMeasurements", PodMeasurements)
Thread::sleep(5000)
} while (!PodMeasurements.contains('"status": "success"'))
var PodTemperature = new Double(transform("JSONPATH", "$.result[0].temperature", PodMeasurements))
var PodHumidity = new Double(transform("JSONPATH", "$.result[0].humidity", PodMeasurements))
postUpdate(Sensibo_Living_Temp, PodTemperature)
postUpdate(Sensibo_Living_Humidity, PodHumidity)
if (!PodMeasurements.contains('"batteryVoltage": null')) {
val Number PodBattery = new Integer(transform("JSONPATH", "$.result[0].batteryVoltage", PodMeasurements))
postUpdate(Sensibo_Living_Battery, PodBattery)
}
}
catch(Throwable e) {
logError("Sensibo measurements", "Error was caught: {}", e)
}
end
rule "Write Sensibo State PodID_01"
when
Item Sensibo_Living_State received command or
Item Sensibo_Living_Mode received command or
Item Sensibo_Living_Fan received command or
Item Sensibo_Living_Swing received command or
Item Sensibo_Living_Target received command
then
try {
//Thread::sleep(1000) // Avoid race condition where state has not yet been updated
var CommandURL = 'https://home.sensibo.com/api/v2/pods/' + PodID_01 + '/acStates?apiKey=' + APIKey
var CommandState = '{"acState":{"on":' + Sensibo_Living_State.state + ','
var CommandMode = '"mode":"' + Sensibo_Living_Mode.state + '",'
var CommandFan = '"fanLevel":"' + Sensibo_Living_Fan.state + '",'
var CommandSwing = ""
if (Sensibo_Living_Swing.state != "")
{ CommandSwing = '"swing":"' + Sensibo_Living_Swing.state + '"}}' }
var String CommandTemp = '"targetTemperature":' + (Sensibo_Living_Target.state as DecimalType).intValue + ','
var String CommandTempUnit = '"temperatureUnit":"C",'
var String CommandData = CommandState + CommandMode + CommandFan + CommandTemp + CommandTempUnit + CommandSwing
var String UpdateResult
var Number Attempts = 0
var CommandExec = 'curl@@-sSH@@"Accept: application/json"@@-H@@"Content-Type: application/json"@@-X@@POST@@-d@@' + CommandData + '@@' + CommandURL
do {
Attempts += 1
//logInfo("Sensibo command", CommandData)
UpdateResult = executeCommandLine(CommandExec, 10000)
//logInfo("Sensibo result", UpdateResult)
Thread::sleep(5000)
} while (!UpdateResult.contains('"status": "success"') && Attempts < 5)
if (Attempts == 5) {
logError("Sensibo write", "5 failures updating Sensibo")
}
}
catch(Throwable t) {
logError("Sensibo write", "Error was caught: {}", t)
}
end
/*** Bedroom Sensibo ***/
rule "Read Sensibo State PodID_02"
when
System started or
Time cron "0 0/5 * * * ?" //Update states from senibo every 5 min
then
//Thread::sleep(1000)
try {
var String PodStatus
do {
Thread::sleep(5000)
PodStatus = executeCommandLine('curl -sSH "Accept: application/json" "https://home.sensibo.com/api/v2/pods/' + PodID_02 + '/acStates?apiKey=' + APIKey + '&limit=1&fields=acState"', 5000)
//logInfo("Sensibo result - PodStatus", PodStatus)
} while (!PodStatus.contains('"status": "success"'))
val String PodOn = (transform("JSONPATH", "$.result[0].acState.on", PodStatus))
val String PodMode = (transform("JSONPATH", "$.result[0].acState.mode", PodStatus))
val Number PodTarget = new Integer(transform("JSONPATH", "$.result[0].acState.targetTemperature", PodStatus))
val String PodFan = (transform("JSONPATH", "$.result[0].acState.fanLevel", PodStatus))
postUpdate(Sensibo_Bedroom_State, PodOn)
postUpdate(Sensibo_Bedroom_Target, PodTarget)
postUpdate(Sensibo_Bedroom_Mode, PodMode)
postUpdate(Sensibo_Bedroom_Fan, PodFan)
if (PodStatus.contains('"swing": ')) {
val String PodSwing = (transform("JSONPATH", "$.result[0].acState.swing", PodStatus))
postUpdate(Sensibo_Bedroom_Swing, PodSwing)
}
}
catch(Throwable t) {
logError("Sensibo read state", "Error was caught: {}", t)
}
end
rule "Read Sensibo Measurements PodID_02"
when
Time cron "0 0/5 * * * ?" //Update states from senibo every 5 min
then
try {
var String PodMeasurements
do {
PodMeasurements = executeCommandLine('curl -sSH "Accept: application/json" "https://home.sensibo.com/api/v2/pods/' + PodID_02 + '/measurements?apiKey=' + APIKey + '&fields=temperature,humidity,batteryVoltage"', 5000)
//logInfo("Sensibo result - PodMeasurements", PodMeasurements)
Thread::sleep(5000)
} while (!PodMeasurements.contains('"status": "success"'))
var PodTemperature = new Double(transform("JSONPATH", "$.result[0].temperature", PodMeasurements))
var PodHumidity = new Double(transform("JSONPATH", "$.result[0].humidity", PodMeasurements))
postUpdate(Sensibo_Bedroom_Temp, PodTemperature)
postUpdate(Sensibo_Bedroom_Humidity, PodHumidity)
if (!PodMeasurements.contains('"batteryVoltage": null')) {
val Number PodBattery = new Integer(transform("JSONPATH", "$.result[0].batteryVoltage", PodMeasurements))
postUpdate(Sensibo_Bedroom_Battery, PodBattery)
}
}
catch(Throwable e) {
logError("Sensibo measurements Bedroom", "Error was caught: {}", e)
}
end
rule "Write Sensibo State PodID_02"
when
Item Sensibo_Bedroom_State received command or
Item Sensibo_Bedroom_Mode received command or
Item Sensibo_Bedroom_Fan received command or
Item Sensibo_Bedroom_Swing received command or
Item Sensibo_Bedroom_Target received command
then
try {
//Thread::sleep(1000) // Avoid race condition where state has not yet been updated
var CommandURL = 'https://home.sensibo.com/api/v2/pods/' + PodID_02 + '/acStates?apiKey=' + APIKey
var CommandState = '{"acState":{"on":' + Sensibo_Bedroom_State.state + ','
var CommandMode = '"mode":"' + Sensibo_Bedroom_Mode.state + '",'
var CommandFan = '"fanLevel":"' + Sensibo_Bedroom_Fan.state + '",'
var CommandSwing = ""
if (Sensibo_Bedroom_Swing.state != "")
{ CommandSwing = '"swing":"' + Sensibo_Bedroom_Swing.state + '"}}' }
var String CommandTemp = '"targetTemperature":' + (Sensibo_Bedroom_Target.state as DecimalType).intValue + ','
var String CommandTempUnit = '"temperatureUnit":"C",'
var String CommandData = CommandState + CommandMode + CommandFan + CommandTemp + CommandTempUnit + CommandSwing
var String UpdateResult
var Number Attempts = 0
var CommandExec = 'curl@@-sSH@@"Accept: application/json"@@-H@@"Content-Type: application/json"@@-X@@POST@@-d@@' + CommandData + '@@' + CommandURL
do {
Attempts += 1
//logInfo("Sensibo command", CommandData)
UpdateResult = executeCommandLine(CommandExec, 10000)
//logInfo("Sensibo result", UpdateResult)
Thread::sleep(5000)
} while (!UpdateResult.contains('"status": "success"') && Attempts < 5)
if (Attempts == 5) {
logError("Sensibo write", "5 failures updating Sensibo")
}
}
catch(Throwable t) {
logError("Sensibo write", "Error was caught: {}", t)
}
end
I hope this helps someone and this wan’t possible without the help from the other users above.