How do I trigger an action based on a device state that hasn't changed?

Forgive me if the title is confusing, basically I have two automations that seem to conflict with eachother:

  1. When motion is not detected for 1 hour, turn off the light.
  2. When the sun sets, turn on the light.

Everything works great, EXCEPT for when there is no motion all day, the sun sets and turns on the light, but then it stays on forever basically until the sun-rise automation turns it off.

I want the light to turn on at sun set, but also turn off after 1 hour if there is no motion. because the motion sensors did not change states, I think it doesn’t trigger…

Anyone know how to fix this?

post your automation for #1

Interested in the answer since apparently we have to jump through hoops on fire to craft a custom automation to notify when a device goes offline

A device going offline changes its state to unavailable. It’s a simple state trigger which can be set up in the UI with a couple of clicks.

No need to

required at all

1 Like

Doesn’t work and nobody cares :

You could have created your own thread and specified which devices & integrations were showing these symptoms, instead of hijacking a thread which had nothing to do with what is causing your issue.

If you had done that (and asked nicely), I probably would have jumped in to help, because I’m 80% certain I know what is causing your issue and how to fix it.

That was before I read your posts in this thread and the one you linked to. I’d rather spend my time helping others who are less entitled and arrogant. Good luck.

So typical of the mentality in most open source project I’m not surprised to say the least. Will just trash this **** and move to another platform… Already wasted to much time on HA which is rigged with bugs

Here is number 1:

description: ""
triggers:
  - type: no_motion
    device_id: bcb26f0dd5bd6dbae44427c08891460a
    entity_id: c2ddf80a96142fda9f16a41952a9568d
    domain: binary_sensor
    trigger: device
    for:
      hours: 0
      minutes: 30
      seconds: 0
conditions: []
actions:
  - action: light.turn_off
    metadata: {}
    data:
      transition: 3
    target:
      device_id:
        - 25820c857c48524f6e8c295ce77df4f7
        - 3683add69011e95d824121828a85ab96
mode: single

I tried to add a timer and a check to my sun-set code:

description: This includes some indoor lights
triggers:
  - trigger: sun
    event: sunset
    offset: 0
conditions: []
actions:
  - action: light.turn_on
    metadata: {}
    data:
      transition: 300
      brightness_pct: 39
    target:
      entity_id: light.outside_fixture
  - action: light.turn_on
    metadata: {}
    data:
      brightness_pct: 35
      transition: 300
    target:
      entity_id: light.outside_fixture_2
  - action: light.turn_on
    metadata: {}
    data:
      transition: 300
      brightness_pct: 40
    target:
      device_id: d9430e61a4d67138ccb55e52d9430dc8
  - action: scene.turn_on
    metadata: {}
    target:
      entity_id: scene.bedroom_relax
    enabled: false
  - action: scene.turn_on
    metadata: {}
    target:
      entity_id: scene.living_room_relax
    enabled: false
  - action: scene.turn_on
    metadata: {}
    target:
      entity_id: scene.office_relax
    enabled: false
  - action: light.turn_on
    metadata: {}
    data:
      transition: 300
    target:
      device_id: fea1c9012c064f072adc17ab0c2edcee
      area_id:
        - office
        - living_room
        - bedroom
  - delay:
      hours: 1
      minutes: 0
      seconds: 0
      milliseconds: 0
  - if:
      - condition: state
        entity_id: binary_sensor.ring_motion_sensor_22725
        state: "off"
        for:
          hours: 0
          minutes: 45
          seconds: 0
    then:
      - action: light.turn_off
        metadata: {}
        data:
          transition: 5
        target:
          area_id: office
  - if:
      - condition: state
        entity_id: binary_sensor.downstairs_motion
        state: "off"
        for:
          hours: 0
          minutes: 45
          seconds: 0
    then:
      - action: light.turn_off
        metadata: {}
        data:
          transition: 5
        target:
          area_id: living_room
mode: single

But it still didn’t work :frowning:

yeah, you can’t do "if"s like that. if checks the current state. also the “for:” approach won’t survive a home assistant restart… ie, if something happens before the 30 minutes are up, it won’t trigger.

what i’d do is to use a timer helper. create a timer. then have 2 audomations: whenever it goes to idle, turn the light off.

then when you have sunset or whenever you have motion, start the timer.

turn the light on as you currently have it. just remove all the current places where you’re turning the light off. let the timer automation do that.

1 Like