Automation Not Firing

I am starting small and simple before expanding and I am not sure why my triggers are not working. I have z-wave working with a GE wall switch and that works both manually and manually in home assistant. I can see the event in my dashboard and it is showing up as default “ON” so that seems right. The entity id was taken from the states page in homeassistant and reads:

switch.__switch_2_0	off	
friendly_name: Post/Garage Light
node_id: 2
icon: mdi:lightbulb-outline

So asking for some guidance. Before I show my example I understand the format is:

  • alias: {{NAME FOR FRONTEND}}
    initial_state: '{{DO YOU WANT IT ON OR OFF}}
    trigger:
    platform: {{THE CONTROL}}
    event: {{AN EVENT VIA THE PLATFORM}}
    offset: "{{TIME OFFSET}}
    action:
    • service: {{WHAT IS TO BE DONE}}
      entity_id: {{THE DEVICE THAT IS CONTROLLED}}

I have in my configuration.yaml:

automation: !include automations.yaml

and inside of automations.yaml I have:

- alias: Driveway lights at night
  initial_state: 'on'
  trigger:
    platform: sun
    event: sunset
    offset: "00:45:00"
  action:
    - service: switch.turn_on
      entity_id: switch.__switch_2_0

- alias: Driveway lights Off
  initial_state: 'on'
  trigger:
    platform: sun
    event: sunset
    offset: "01:30:00"
  action:
    - service: switch.turn_off
      entity_id: switch.__switch_2_0

- alias: Driveway lights Off during the day
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: switch.__switch_2_0
    state: 'on'
  condition:
    - condition: state
      entity_id: sun.sun
      state: 'above_horizon'
  action:
    - service: switch.turn_off
      entity_id: switch.__switch_2_0

Two things:

Do you see the “automations” card in the frontend? Can you click on the Automation and then click on “Trigger” to trigger it? If yes, your action is fine. If not, you need to look at the action portion of your automation and see if the command or the entity_id is wrong…

1 Like

@BendedArrow Yes I can see it and when I click the trigger it doesn’t work. Based on what you said I know the ID is 100% correct but I cannot be sure about the service.

How do I find out what the service should be?

You should confirm the entity_id. There is also a different action for dimmers (light.turn_on") and for switches (switch.turn_on).

Go to Developer Tools and click on < >. Uncheck attributes. Find what you think is your device and manually turn the switch on and off and see if the state changes to on and off to confirm that is the entity ID you are working with…

Ok, so that worked. and the state changed. When the Driveway lights Off during the day automation saw the light turn on it turned it back off so I will give it another go tonight and see if it works.

Thanks for walking me through this!

By default, the initial state of an automation is on, so you do not need to put the initial_state directive in there…

As read, your first automation should turn on the switch.__switch_2_0 light 45 minutes after sunset

Your second automation should turn the switch.__switch_2_0 light on 1 1/2 hours after sunset.

The last automation is confusing: as written should turn the switch.__switch_2_0 off when the sun is above the horizon and the switch is on, which is a conflict. Whenever the driveway light is on (the trigger), and the sun is above the horizon, it will turn the switch off… If you wanted to turn off the driveway light off at sunrise, you should do this:

  trigger:
    platform: sun
    event: sunrise
  condition:
    condition: state
    entity_id: switch.__switch_2_0
    state: 'on'
  action:
    - service: switch.turn_off
      entity_id: switch.__switch_2_0