Turn a device off during a certain period when state changes

I have a lightbar that for some reason decides to turn on randomly throughout the day and night. I’ve already done all of the troubleshooting with Tuya, they say the manufacturer has to push a firmware update. In the meantime, I’m not so concerned with the day/evening, but from 12 midnight until 8am I would like an automation to detect a state change (on) and trigger an (off) command. I did set up an automation that if another device is off, that this troublesome lightbar will turn off too, but that only works when I trigger the other device to go off once. Is there a way to monitor a device/entity state during a time of day and have it watchdog it to flip it back off?

  • State trigger watching for the state to go on
  • Time condition for the timespan you want
  • Service turn_off action.

Job done. Which bit are you struggling with?

trigger:
  - platform: state
    entity_id: light.why_does_noone_ever_include_their_actual_entity_ids_in_questions
    to: 'on'
condition:
  - condition: time
    before: "08:00"
action:
  - service: light.turn_off
    target:
      entity_id: light.why_does_noone_ever_include_their_actual_entity_ids_in_questions

image

1 Like

Thank you so much Troon! that worked, I didn’t see an option for “State” in trigger until I started typing it (I guess it was hidden?), but I think that is exactly what I wanted. Much appreciated! This gives me all kinds of ideas now.

1 Like

It’s under “Entity”. The focus in the UI on “Device” causes far more problems than it solves.

You don’t actually need the “after 12:00am”, which is why I didn’t:

Note that if only before key is used, the condition will be true from midnight until the specified time.

1 Like

:joy:

P.S. I see that it’s actually much better now. I never use the UI so never noticed.

1 Like

It’s really coming on quite nicely now. I still use YAML for pretty much everything, but I’m far less of a UI-Luddite than I used to be :grin:.

1 Like