Creating a rule with a delay in it

Hi All.
i have a problem and seems that i cant get it to function.
i have a sonoff t1-2 gang that controlls my lights in my geust bedroom. i also added a ifan 2 to the fan/light combo in the room.
my issue starts with when you turn on the liht/fan the light comes on but i have the option for 3 types of tempretures on the led light. so i added a switch that only apears when the main light switch is on. that gives me the option to change the fan speed. and also turn the light on and of. .

what i need to do now is to have the status updated to the switch as when you turn the light on from the t1. the sitmap gives me the other options but it does not update to say that the light is on now. and the other isue is if the fan is running and you turn it off and back on with the t1 the sitmap shows it is still on set speed but the fan is off.

i run tasmota on bouth the sonnofs.
please see sitmap and rules i tried to get this working.

Sitemap :

ext label="Master-Bedroom" icon="bedroom"{
         Default item=MasterBedroom_Light_Ingan label="Light" icon="lightbulb"
         Default item=MasterBedroom_Light label="Entrance Light" icon="lightbulb"
         Default item=MasterBedroom_Fan_Light  label="Fan Light"  icon="fan_ceiling" visibility=[MasterBedroom_Light_Ingan==ON]
         Switch item=MasterBedroom_Fan_spd label="Fan Speed" icon="fan_ceiling"  mappings=[0="OFF", 1="Slow", 2="Med", 3="High"] visibility=[MasterBedroom_Light_Ingan==ON]
         Default item=MasterBedroom_Humidity label="Humidity [%.1f %%]"
         Default item=MasterBedroom_Temperature  label="Temperature [%.1f °C]"
      }

Items for the Rule :

Switch  MasterBedroom_timer     "timer"               {expire="5s,command=OFF"}

Rule :

rule "Main bedroom fan Timer"
when
    Item MasterBedroom_Light_Ingan  changed from OFF to ON
    
then

  MasterBedroom_timer.sendCommand(ON)
  MasterBedroom_Fan_spd.postUpdate(0)
  logInfo("Rule","Fan switch Timer Start")
 
end

rule "Main bedroom fan corection"
when
    Item MasterBedroom_timer  changed to OFF
    
then

  MasterBedroom_Fan_Light.postUpdate(ON)
  MasterBedroom_Fan_spd.postUpdate(0)
  logInfo("Rule","Fan switch update On")
 
end

Status to what switch? Updated to what?

The sitemap shows Item’s states. Are you saying that the Item is not updating or you don’t have the Item on the sitemap or something else?

Well, you fan turned from OFF to ON sets the spd Item to 0. So it’s showing what you told it to. You need to set the speed to perhaps the last state before it was turned off.

Thanks for the reply.

The switch that indicates that the fan light is on. When i turn the fan on via the sonnof t1. The switch that controls the fan light becomes visible and its state stays in the off position. I want to have that to be updated to the on position. As the light comes on automatic when you turn the fan on.

Kind regards / vriendelijke groeten
Allen
Africa AVC

Is the problem that your are updating the item but the sitemap isn’t showing that it’s updated, or you don’t know how to update the Item?

I write the update but it goes back to off. Thats why i want to have a delay to alow the ifan to start completely before i write the update to the site map

Kind regards / vriendelijke groeten
Allen
Africa AVC

What is setting it back to OFF. This sounds like an XY Problem which is why I’m asking all these questions. A delay may work but it’d probably just be covering up the root problem.

How do you post the update? From the sitemap? A rule different from those you posted above?

I first had the rule. With out a dummy switch. But now i tried using the dummy switch but seems not to help eather. Will load all the codes once i get to my laptop

Kind regards / vriendelijke groeten
Allen
Africa AVC

ext label="Master-Bedroom" icon="bedroom"{
         Default item=MasterBedroom_Light_Ingan label="Light" icon="lightbulb"
         Default item=MasterBedroom_Light label="Entrance Light" icon="lightbulb"
         Default item=MasterBedroom_Fan_Light  label="Fan Light"  icon="fan_ceiling" visibility=[MasterBedroom_Light_Ingan==ON]
         Switch item=MasterBedroom_Fan_spd label="Fan Speed" icon="fan_ceiling"  mappings=[0="OFF", 1="Slow", 2="Med", 3="High"] visibility=[MasterBedroom_Light_Ingan==ON]
         Default item=MasterBedroom_Humidity label="Humidity [%.1f %%]"
         Default item=MasterBedroom_Temperature  label="Temperature [%.1f °C]"
      }

as above when i turn on the light (MasterBedroom_Light_Ingan) be it on the visical switch or on the site map (the fan light comes on as automatic )(firmware on sonofs tasmota). the fan light and fan spd. becomes visible.
but the fan light shows that it is off. and the fan speed still shows the previous state. being the last speed when i turn it off be it via the visical switch or with openhab…

so my first attempt on the rule looked like this.

rule "Main bedroom fan corection"
when
    MasterBedroom_Light_Ingan  changed from OFF to ON
    
then

  MasterBedroom_Fan_Light.postUpdate(ON)
  MasterBedroom_Fan_spd.postUpdate(0)
  logInfo("Rule","Fan switch update On")
 
end

thus updated the status of the light but then it turned off again. then you need to turn the switch on in openhab to sync it to the fiscal light.

then i searched some more. and saw that you could use a none bound switch with a expire time on it to triger the rule. so tri number 2:

rule "Main bedroom fan Timer"
when
    Item MasterBedroom_Light_Ingan  changed from OFF to ON
    
then

  MasterBedroom_timer.sendCommand(ON)
  logInfo("Rule","Fan switch Timer Start")
 
end

rule "Main bedroom fan correction"
when
    Item MasterBedroom_timer  changed to OFF
    
then

  MasterBedroom_Fan_Light.postUpdate(ON)
  MasterBedroom_Fan_spd.postUpdate(0)
  logInfo("Rule","Fan switch update On")
 
end

But now it seems to not be working. i will make a short video in the morning to show what actually happens.

That’s the root of the matter. What turned it off again? The Binding? Is the Item really ON but the sitemap is showing it as OFF?

The difference here is that you are sending a command, not posting an update.

The problem is figuring out why it’s being turned off again and that’s not being done by your rules.In all likelihood it’s the binding that is updating the Item with what the binding things is the state of the device. No amount of delay in the rule will fix that. You need to figure out why the binding keeps turning the Item back to OFF.

It uses mqtt.

Kind regards / vriendelijke groeten
Allen
Africa AVC

OK, and does the status get published periodically or is the message on the topic subscribed to retained?

yes it is periodically

if i look at the logs on the ifan it is not retained

here is the part of my mqtt.thing.

Thing topic master_bed "MasterBedroom"{ 
    Channels:
    Type switch : lamp                              "Main_Light"                [ stateTopic="HoofSlaapKamer/relay/0", commandTopic="HoofSlaapKamer/relay/0/set" , transformationPattern="MAP:OFF0ON1.map" , on="ON", off="OFF" , 1="ON" , 0="OFF" ]
    Type switch : downlight                         "downlight"                 [ stateTopic="HoofSlaapKamer/relay/1", commandTopic="HoofSlaapKamer/relay/1/set" , transformationPattern="MAP:OFF0ON1.map" , on="ON", off="OFF" , 1="ON" , 0="OFF" ]
    Type number : temp                              "MasterBedroom Temp"        [ stateTopic="Sensor POD 1/DHT11/Temperature"] 
    Type number : humi                              "MasterBedroom Humidity"    [ stateTopic="Sensor POD 1/DHT11/Humidity"]
    Type switch : Fan_Light                         "Fan on/off"                [stateTopic="stat/Masterbedroom-Fan/power", commandTopic="cmnd/Masterbedroom-Fan/power"]
    Type number : Fan_SPD                           "Fan Speed"                 [stateTopic="stat/Masterbedroom-Fan/Fanspeed", commandTopic="cmnd/Masterbedroom-Fan/FanSpeed", transformationPatter="JSONPATH($.FanSpeed):(*)"]
    
  }

My items file for that.

Switch  MasterBedroom_Fan_Light       "Fan Light"                      <fan_ceiling>    (MasterBedroom)                                  {channel="mqtt:topic:mosquitto:master_bed:Fan_Light"}
Number  MasterBedroom_Fan_spd         "Fan Speed"                      <fan_ceiling>    (MasterBedroom)                                  {channel="mqtt:topic:mosquitto:master_bed:Fan_SPD"}

Sitemap :

Frame label="Rooms"{
      Text label="Master-Bedroom" icon="bedroom"{
         Default item=MasterBedroom_Light_Ingan label="Light" icon="lightbulb"
         Default item=MasterBedroom_Light label="Entrance Light" icon="lightbulb"
         Default item=MasterBedroom_Fan_Light  label="Fan Light"  icon="fan_ceiling" visibility=[MasterBedroom_Light_Ingan==ON]
         Switch item=MasterBedroom_Fan_spd label="Fan Speed" icon="fan_ceiling"  mappings=[0="OFF", 1="Slow", 2="Med", 3="High"] visibility=[MasterBedroom_Light_Ingan==ON]
         Default item=MasterBedroom_Humidity label="Humidity [%.1f %%]"
         Default item=MasterBedroom_Temperature  label="Temperature [%.1f °C]"
      }

MQTT explorer info for the ifan.

State :

{"Time":"2020-12-24T10:17:56","Uptime":"0T00:05:37","Heap":16,"SleepMode":"Dynamic","Sleep":50,"LoadAvg":19,"POWER1":"OFF","FanSpeed":1,"Wifi":{"AP":1,"SSId":"Slaghuis-Auto","BSSId":"EC:AD:E0:CB:61:6F","Channel":13,"RSSI":68,"LinkCount":1,"Downtime":"0T00:00:03"}}

It sounds like the Item is getting reset with an update message from the device which is going to switch it back to the OFF state. Or the binding sees that the Item is different from the last message received so it sets it back to OFF.

It might work if you sendCommand instead of postUpdate. But it is clear that adding a delay before calling postUpdate isn’t going to work.