Simple GUI rule turning hue scene at night time after presence detected

I’ve managed to create my first working rule in OH (the new OH 3 is awesome😎 btw), but I wonder how to make it expire after certain amount of time, eg turning hue o off 5 min after last detection of movement.
I came to point where (I believe) I need to use some script to create expiry timer, but as I don’t have serious programming skills (I’m a surgeon😅) I don’t know how to start.

  • id: “3”
    command: ON
    itemName: PIRLazienkaZach
    type: core.ItemCommandTrigger
  • id: “4”
    itemName: PIRLazienkaZach_Violation
    state: ON
    type: core.ItemStateUpdateTrigger
  • inputs: {}
    id: “1”
    itemName: MainBathroomHueRoom_Switch
    state: OFF
    operator: =
    type: core.ItemStateCondition
  • inputs: {}
    id: “2”
    startTime: 23:00
    endTime: 07:00
    type: core.TimeOfDayCondition
  • inputs: {}
    id: “5”
    itemName: MainBathroomHueRoom_Scene
    command: f9XS7EmVVV5ve0a
    type: core.ItemCommandAction

Hi there

You could do it by a rule or by setting Expire in the metadata of the item. Simply Settings/Items, find the Item and select add Metadata/Expiration Timer. Under Do, use send command, OFF.

That way you could trigger it on and it auto expires after a time that suits.

1 Like

I’ll dig into this today👍🏼
Thank you🙂
When I create working rule, I’ll post it here. Maybe it will be off some use for someone.

Expire is the best solution if that light is only ever controlled by the motion detector or the light should always turn off five minutes after the last time it was updated.

However, if you want to control the light in other ways, you will need a rule with a Timer.

Design Pattern: Motion Sensor Timer will give you a bit of the theory behind something like this will work and some examples. But I’ve not yet updated it to OH 3 UI rules yet so come back and ask if you need help translating from the examples there to the UI. If you have a basic understanding of rule triggers and actions it shouldn’t be too hard.

There is also an example showing how to use Expire there to solve this as well.

1 Like

I’ve made it, but it wasn’t as straightforward as I anticipated ¯\(ツ)
First of all I created “virtual” switch which acted as a proxy for Satel PIR - Occupancy_Bath with metadata expiration timer 5 min and OFF command.

next I’ve created rule which updated Occupancy_Bath to ON state after PIR sensor violation

next was creating rule which actually turned on predefined hue scene (f9XS7EmVVV5ve0a) in bathroom, but only if light wasn’t ON manually and time of the day was between 10pm and 7am

problem was that ccupancy_Bath switch with metadata expiration timer doesn’t turned hue off by itself [don’t know why, yet], so next rule was to turn of hue

It works… but I have unpleasant feeling it is too complicated, and i’ve missed sth.

probably if it was possible to create direct link to hue lights in that switch, last rule would be unnecessary.

It worked - I’ve created new item from hue thing with metadata expiration :upside_down_face:

:anger: NO it doesn’t worked - state of scene is updated to OFF but it doesn’t turn off lights :thinking:

You have to put the expire on the light. The rule triggers on the motion to turn on the light. Repeated motion commands the light on again, restarting the expire. Only sheet 5 minutes of no on commands with the light turn off.

In short, put the expire meadata. on your light items, not the occupancy item.

Yes, finally I did it this way, but I’ve tried more sophisticated solution. My plan was to turn night scene in night only, and light expiring only if it was turned by PIR sensor, not expiring if it was turned on by hand. AND also not to change scene if the light was already turned on. I planned to create special scene for that, and set expiry metadata on it, but it seems that sending OFF command to scene by expiry metadata doesn’t turn off light actually. Also creating separate expiring item switch from thing channel does’t worked as this new separate item turns on along with other item created on that particular channel ¯\(ツ)
So finally my working rule is like that :slight_smile:

  • expiring light switch, not scene, as command turning OFF don’t worked for scene

    Iv’e set condition IF Bathroomsw_DimmerSwitchState>4000 to limit rule execution to situation when light is not turned on manually

You’re gonna need a rule for all that.

Let’s take a step back. Expire only works on the single Item that it is configured on. So if you have it configured on Item Foo, then Foo will receive the command OFF when Expire goes off. If you need to cause other items to change states too, you will need to write a Rule that triggers when Foo goes OFF and sends the commands to the other Items.

I’m glad you got it working in the end. It’s not as important for this particular rule, but it will be good to get in the habit of posting the actual code instead of screen shots. Screen shots usually do not capture everything on needs. There is a code tab at the top of that page. Paste that text into the post and use code fences to preserve the indentation.

code goes here