@EBF
You test with PodID_01, so you must change the PodID to PodID_01 in your rules.
And your items is Sensibo_***_***, so you must change to that items
rule "Read Sensibo State PodID_01"
when
System started
then
Thread::sleep(10000)
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)
} 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))
if (PodOn == "true")
{ postUpdate(Sensibo_Living_State, ON) }
if (PodOn == "false")
{ postUpdate(Sensibo_Living_State, OFF) }
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 * * * ?"
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)
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 changed 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 Boolean PodBoolean
if (Sensibo_Living_State.state == ON)
{ PodBoolean = true }
else
{ PodBoolean = false }
var CommandURL = 'https://home.sensibo.com/api/v2/pods/' + PodID_01 + '/acStates?apiKey=' + APIKey
var CommandState = '{"acState":{"on":' + PodBoolean + ','
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 CommandData = CommandState + CommandMode + CommandFan + CommandSwing + CommandTemp
var String UpdateResult
var Attempts = 0
do {
Attempts += 1
logInfo("Sensibo command", CommandData)
UpdateResult = executeCommandLine('curl@@-sSH@@"Content-Type: application/json"@@-XPOST@@' + CommandURL + '@@-d@@'+ CommandData, 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