Basic automation not firing

I’m very new to HA but I’ve been playing around and now I’ve got stuck. I bought a Tradfri Bulb and Motion Sensor which I’ve connected via a Zigbee gateway (Phoscon). I ran through the automations tutorial and everything worked - when I wave my hand the light turns on wohooo!

Unfortunately it seems that not everything is simple, trying to do the reverse and turn the light off when the sensor goes “Clear” seems much more difficult. Here is my automations.yaml

- id: '1558122946947'
  alias: LightOn
  trigger:
  - entity_id: binary_sensor.tradfri_motion_sensor
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      entity_id: light.lamp
    service: light.turn_on
- id: '1558378378087'
  alias: LightOff
  trigger:
  - entity_id: binary_sensor.tradfri_motion_sensor
    to: 'off'
    platform: state
  condition: []
  action:
  - data:
      entity_id: light.lamp
    service: light.turn_off

To me the automations look exactly opposite. The first works and the light turns on, the second does not and so the light stays on :frowning:

Looking at the LogBook I can see the ‘on’ event followed by the ‘LightOn’ automation then I can see the ‘off’ event but no ‘LightOff’ automation. I’m not sure what else to check… help?

I also tried using the trigger
from: ‘on’
rather than
to: ‘off’
but that was no more successful.

Did you check to see if the automation is turned “on” that seems to happen a lot lately where it is not activated at first

You can add initial_state: on so it always is on after a reboot or whatever

I’m not quite sure what you mean - how do I check that?

Go to states page < > find the automation and you will see on or off after it …

It seems it’s not turned on, strangely I seem to have 3 automations despite there being only two in the automations file (that was the whole file!)

|automation.lightoff |off|
|automation.lighton |off|
|automation.lighton_2 |on|

Should I just use this page to set the attributes to true or…?

Is the automation enabled?
Look in the developer tools states menu for automation.lightoff It’s sate should be on.

Yes looks like it was off and turning it on works.
Is there any other way to turn an automation on? It seems quite hidden away!

Two things:

  1. Make entities cards with your automations. I group mine into cards like, Alert automations, light automations, etc… Put the cards in a view.
  2. Include an initial state in your automation so it is always on (or off) after restart.
- id: 'blah'
  alias: blahblah
  initial_state: true
  trigger:
...

Thanks, I’ll take a look :slight_smile: