Harmony Hub and delayed turning lights off with scene change help

Hi all

I have a automation that I have created but having problems with light timers

So, I have created

When:
Harmony hub activities changed
Sky to off

And if:
Confirm time is after 15:00 and before 1:00

Then do:
Turn off lights

Now what I would like to do is let’s say I want to turn off the hub from sky and it’s between 15:00 and 10:30 i would like the lights to stop on until 10:30 regardless what time I turn the hub of between 15:00 and 10:30. Also if I turn the hub off after 10:30 and before 01:00 to turn the lights off in 1 min of turning the hub off

I can not get this to work as every time I turn the hub off it will turn the lights off after 1 min which is fine after 10:30 but any time before that I want the lights to stay on until 10:30.

I hope you can all help as it would have been ideal if the (then do:) had a set time option to turn the lights of before set times and after.

Thanks for any help

you should post your automation, otherwise it’s kinda hard to determine what’s wrong.

Is this what you want ?

Here is a good link to format your code properly. It helps expedite a solution

See #11

1 Like

it would really help if you did the formatting as @LiQuid_cOOled indicated. makes it easier for us to edit your automation.

a few questions for you

  1. you said:

do you mean that you would like the lights to stay on until 10:30?

  1. if the lights are on because someone turned them on, but the hub never turned on or off between 15:00 and 10:30, do you want the ligthts to turn off at 10:30? in other words, do you want the lights to turn off always at 10:30 unless the hub is still on? or do you want them to turn off only if the hub was turned off during that time?

if you want the lights to turn off always at 10:30 unless the hub is on, that’s super easy… just create an automation that triggers at 10:30 and conditions that the hub is off then turn the light off.

Sorry new to home assistant as just installed it a week ago and learning all the time, I will post the script properly when back at home as now left and can not access the system.

What happens is we watch tv and when it gets dark the lights come on which is not the problem, So

Sometimes I stay up late let’s say 23:00 and I turn the lights off but instead I did a automation that when I turn the tv off which is controlled by the harmony hub, the state changes from anything on scene to off it then triggers the lights to go off after 1 min delay, Perfect. I set this to work between 22:30 and 01:00 and works great if I turn the hub off after 22:30 time frame.

Now The problem, let’s say instead I am abit tired and want to go to bed early say 20:00 and I turn of my Tv using the harmony state again changes from on to off which works, But this time I wanted The lights to stay on and wait until 22:30 then turn the lights off as the harmony has changed it state a couple of hours ago. But what happens is the lights stay on after 22:30 has passed and nothing happens as the trigger happened before the 22:30 and not after.

So basically turn the lights off straight away after 22:30 when harmony hub is off and anything before that time leave the lights on up until 22:30 then turn the lights of when harmony hub is off

Hope I explained that abit better

Sorry

Cany you clarify the times?
The orginal post stated
Confirm time is after 15:00 and before 1:00

The script shows

after: ‘18:00:00’
before: ‘01:00:00’

Your last post states

I set this to work between 22:30 and 01:00 and works great if I turn the hub off after 22:30 time frame.

1 Like

i got all that, but the scenario you didn’t clarify that i was asking about is what if someone turns the lights on at 19:00 manually. the harmony is off and stays off. what do you want to happen? do you want it to turn off at 22:30 also? or in that case do you want it to stay on?

if you want it to turn off at 22:30 also, then the “stay on if i turn it off earlier” is really immaterial… and all you’re saying is “turn the lights off always at 22:30 unless harmony is on… in which case turn it off 1 minute after harmony turns off”… which is super easy.

Sorry changed it back to 22:30 I was playing around with it and changed it to 18:00 but I should have put it back to 22:30.

Was seeing if that what was causing it

Problem with changing it to 18:00 it now works in that time frame but the lights go off after 1 min and don’t stay on till 22:30.

That time seem to be when the trigger has to be in that time frame to trigger and not controlling the lights time frame.

No worries, just trying to clarify as you have multiple scenarios in play.

No I don’t want anything to happen to the harmony hub all I am wanting to do is asking home assistant to monitor harmony hub state and if the state is off between 18:00 and 22:30 turn the lights of at 22:30 if it’s after 22:30 and the harmony hub state is off turn the lights off after 1 min delay

So if any of the harmony hub state is other than off it will Just ignore it and leave the lights alone meaning on until the state changed to off

If someone tuns the lights on the harmony hub does nothing what ever state it’s in apart from if it changes its state to off which is the trigger

Remember when the harmony is not been physically turned off by power it just a state change from something been on and the harmony hub changes to off in home assistant

that’s not my question… lemme try again.

if someone turns on the lights. and no one touches the harmony hub. the hub is off. was off all day. never on. what do you want to happen to the lights at 22:30?

Ah right. Nothing. As I have a room sensor that controls that

So basically two actions

  1. If the Harmony Hub is turned off between 18:00 and 22:30 manually turn the lights off.

  2. If the Harmony Hub is off after 22:30, turn the lights off.

Will the Harmony Hub turn it’s self off after a certain timeframe?

i think its this:

  1. If the Harmony Hub is turned off between 18:00 and 22:30 have HA turn the lights off at 22:30. (note, i’m unclear why the room sensor wouldn’t turn the light off as in case 3)

  2. If the Harmony Hub is off after 22:30, turn the lights off after waiting 1 minute after the hub is off.

  3. if the light is on manually and the hub was never turned on, leave the light on

  1. If the Harmony Hub is turned off between 18:00 and 22:30 manually turn the lights off after 22:30.

  2. If the Harmony Hub is off after 22:30, turn the lights off straight away with a 1 min delay.

The harmony hub is always powered on but in home assistant it has a scene selection eg

Sky
Xbox
Pc
Off

So when watching anything it will be in either sky, Xbox, pc and when I turn it off sky it goes into the off state in home assistant

try something like this. replace the entities i’ve used with your entities.
don’t use device_id’s. use friendly name entity_id’s like i did.

@LiQuid_cOOled would love your eyes on this to catch if i screwed something up… i free handed this, and didn’t test it…

mode: single
trigger:
  - platform: time
    at: "22:30:01"
    id: time
  - platform: state
    entity_id:
      - remote.harmony_hub
    to: "off"
    for:
      minutes: 1
    id: hub1min
condition:
  - condition: time
    after: "22:30:00"
    before: "01:00:00"
  - condition: state
    entity_id: remote.harmony_hub
    state: "off"
    for:
      minutes: 1
action:
  - if:
      - or:
          - condition: trigger
            id:
              - hub1min
          - and:
              - condition: trigger
                id:
                  - time
              - condition: template
                value_template: >-
                  {{ states.remote.harmony_hub.last_changed > today_at('18:00')
                  }}
    then:
      - service: light.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: light.great_room_lights

note however, that there are a number of scenarios that are still wonky. so consider doing this simplfiied approach which i think @LiQuid_cOOled and i both prefer… but this does turn off the lights at 22:30 if the harmony is off, regardless of why it’s off.

trigger:
  - platform: time
    at: "22:30:01"
  - platform: state
    entity_id:
      - remote.harmony_hub
    to: "off"
    for:
      minutes: 1
condition:
  - condition: time
    after: "22:30:00"
    before: "01:00:00"
  - condition: state
    entity_id: remote.harmony_hub
    state: "off"
    for:
      minutes: 1
action:
  - service: light.turn_off
    target:
      entity_id: light.great_room_lights

Cheers all I will try it out when I get home tonight

Once again thanks for all this newbie questions. Have to admit it’s very addictive trying to get things working the way you want. lol love it

Testing it now

1 Like

yeah, i think many of us find it pretty fun.

as you learn all of this, one piece of advice is that home automation gets messy and error prone if you think and program in a “state machines” mindset. ie, “when this happens then later do that” or even worse is multi-step state machine… “when this happens, wait until that happens, etc, then do x”

your inital mindset “if i turn off the harmony hub, then later at 22:30 turn the lights off”… that’s a state machine mindset.

what my code did was to reframe it as a rule:
turn the light off when:
the harmony hub has been off for at least a minute and also it’s past 22:30

hopefully that makes sense…