Sonoff TH16 Update TelePeriod

Hi, this is my first post all though i have been learning a lot from this forum for the past 6 months or so!

I am still learning OpenHab and all its useful application and so far i have successfully configured a working smart home environment and consider myself fairly capable but this 1 thing is besting me, i hope someone can point me in the right direction.

I have an electric heater that i monitor the supply temperature of, works well and using the sonoff device flashed with Tasmota i can obviously set the TelePeriod as needed, however i am trying to set it through a rule to more frequent when on and less so when off. Pretty simple ey!

Using mqttfx i can send the relevant command and update the TelePeriod so i know that side of things is ok but using the postUpdate command in a rule will set the Item to the required number but will not publish the command.

My item is set up as below:

Number   GF_Conservatory_SupplyTemp_TelePeriod "Heater Teleperiod [%d s]" (GF_Conservatory)                                                    {mqtt=">[broker:cmnd/sonoffs_conservatory/TelePeriod:command:*:default],<[broker:stat/sonoffs_conservatory/RESULT:state:JSONPATH($.TelePeriod):.*TelePeriod.*]", autoupdate="false"}

and my rule looks like this

rule "Heater Supply Temp Reporting"

when 

Item GF_Conservatory_Power changed

then

if (GF_Conservatory_Power.state != ON){ GF_Conservatory_SupplyTemp_TelePeriod.postUpdate (1800) 
logInfo("Heater Control", "Supply Temp Teleperiod set to every 30 minutes" )

}else if (GF_Conservatory_Power.state === ON) {

 GF_Conservatory_SupplyTemp_TelePeriod.postUpdate (300) 
logInfo("Heater Control", "Supply Temp Teleperiod set to every 5 minutes") }

end

I have other rules using similar set ups that work so i suspect its something i’m missing in the item.

I have tried everything i can think of, and searched for hours for a solution. Where am i going wrong?

What do you see in the logs?

i don’t get any errors, this is the line as it triggers:

9:32:41.108 [INFO ] [smarthome.event.ItemStateChangedEvent] - GF_Conservatory_Power changed from OFF to ON
19:32:41.121 [INFO ] [smarthome.event.ItemStateChangedEvent] - GF_Conservatory_SupplyTemp_TelePeriod changed from NULL to 300
19:32:41.123 [INFO ] [smarthome.model.script.Heater Control] - Supply Temp Teleperiod set to every 5 minutes

Use a tasmota rule.
They are coded inside the tasmota.
See the tasmota docs. I am on my phone right now so I don’t have the link.
It’s pretty easy.

That’s because you must sendCommand to cause the binding to react. postUpdate only updates the Item’s state within openHAB. If you want MQTT to publish a message, you must sendCommand.

I also notice you are using the MQTT v1 style binding config on your Item. Do you have the MQTT v1 binding installed and properly configured? If not, the MQTT 2 binding configuration and use is totally different. See Search results for 'MQTT migration' - openHAB Community for lots of examples for how to move what you have to the v2 approach.

thanks @rlkoshak i have tried it with .sendCommand but it still doesn’t send it to the sonoff device.

Rule with .sendCommand

rule "Heater Supply Temp Reporting"

when 

Item GF_Conservatory_Power changed

then

if (GF_Conservatory_Power.state != ON){ GF_Conservatory_SupplyTemp_TelePeriod.sendCommand (1800)
logInfo("Heater Control", "Supply Temp Teleperiod set to every 30 minutes" )

}else if (GF_Conservatory_Power.state === ON) {

 GF_Conservatory_SupplyTemp_TelePeriod.sendCommand (300) 
logInfo("Heater Control", "Supply Temp Teleperiod set to every 5 minutes") }

end

Log entry

22:13:03.991 [INFO ] [smarthome.event.ItemStateChangedEvent] - GF_Conservatory_Power changed from ON to OFF
22:13:03.994 [INFO ] [smarthome.model.script.Heater Control] - Supply Temp Teleperiod set to every 30 minutes
22:13:03.998 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'GF_Conservatory_SupplyTemp_TelePeriod' received command TelePeriod 1800

I have mqtt 2.4 i am looking at migrating all my links i just haven’t got round to it :roll_eyes:

Well, your Item is a v1 configuration. It’s not going to work unless you have MQTT v1 installed and correctly configured.

Thanks @vzorglub i may take a look at this, i’m after something a little more dynamic though as there are several virtual switches i would like to include in this rule

You’ll have to excuse my ignorance i am not fully versed in the compatibility of mqtt 1.x and 2.x but if 1.x format doesn’t work with 2.x format surely nothing would work?

everything i built started off as 1.x then i upgraded OH and MQTT and left my 1.x bindings in place and have just carried on with it, everything else works without issue, a couple of examples below:

Switch   GF_LivingRoom_Light        "Frontroom Light"     <light>         (GF_LivingRoom, gLight)        ["Lighting"]          {mqtt=">[broker:cmnd/sonoffsw_frontroom/POWER1:command:*:default],<[broker:stat/sonoffsw_frontroom/POWER1:state:default]", autoupdate="false"}
Switch   GF_LivingRoom_Power        "Front Room Lamp"     <poweroutlet>   (GF_LivingRoom, gPower)        ["Switchable"]         {mqtt=">[broker:cmnd/sonoffs_frontroom/POWER:command:*:default],<[broker:stat/sonoffs_frontroom/POWER:state:default]", autoupdate="false"}
Switch   GF_Kitchen_Light           "Kitchen Light"       <light>         (GF_Kitchen, gLight)           ["Lighting"]             {mqtt=">[broker:cmnd/sonoffsw_frontroom/POWER2:command:*:default],<[broker:stat/sonoffsw_frontroom/POWER2:state:default]", autoupdate="false"}

There is no compatibility.

Correct. But the fact that you have some MQTT v1 Item working, and therefore have the MQTT v1 binding installed and correctly configured was not clear. That’s why I kept repeating that part.

Personally, I would sit back and consider whether it is worth continuing to try to figure out why this is not working, or switch to using the 2.x binding for this Item if you plan on moving to 2.x binding anyway.

If you want to continue to debug, you need to put the MQTT binding into debug mode and see if there is anything interesting when the .items file is loaded and/or when you sendCommand to the Item.

I do this in my power monitor for the washing machine
rule1 ON Energy#Power>0 DO Teleperiod 10 ENDON ON Energy#Power=0 DO Teleperiod 300 ENDON
rule1 on

This way the power monitor reports every 10s when the washing machine is on and only every 5 minutes when off.