MyQ Automations Not Working

Hello, I am trying to turn on a smartswitch when my garage door opens. This is what I have in my automation file and it is not working, or even being triggered.

Does this look correct to you?

- alias: Garage Fan Toggle With Garage Door
  trigger:
    - platform: state
      entity_id: cover.mike
      to: 'open'
  action:
    - service: switch.turn_on
      entity_id: switch.garage_fan_mike

add "initial_state: ‘on’ " to the automation.

- alias: Garage Fan Toggle With Garage Door
  initial_state: 'on'
  trigger:
    - platform: state
      entity_id: cover.mike
      to: 'open'
  action:
    - service: switch.turn_on
      entity_id: switch.garage_fan_mike

That worked! Thank you!

I’m trying to do almost exactly the same thing, only thing is, I’m trying to understand it more generally than just this specific problem. Can you clarify why we need to initial state setting?

If you are using version 0.94 or higher, there’s no pressing need to use it. If you are in the habit of manually turning off an automation, then forgetting to turn it back on, initial_state: true will automatically turn on the automation when Home Assistant starts. Conversely, if you have an automation that you use very rarely (it’s normally turned off), adding initial_state: false to it will ensure it is always turned off on startup.

If you don’t use initial_state, Home Assistant’s restore feature will set the automation to whatever state it was in prior to the restart. If it was on it is restored to on. If it was off, it’s restored to off.

If you are using a version that’s older than 0.94, then there’s another use for initial_state. Prior to 0.94, there was a bug in the restore feature. Sometimes on startup it would turn off automations. That would happen without you knowing it. There are dozens of posts in this forum asking why an automation refuses to trigger, only to discover the answer is simply because the automation is off! The first post in this thread is an example of that. The bandaid solution to the restoration bug was to simply slap initial_state: true onto every automation to ensure it wouldn’t get turned off.

Anyway, that’s all ancient history and the bandaid is no longer needed, provided you are using version 0.94 or higher.

Cool, just getting started with automations, so trying to make sure I understand the basic syntax (first project is going to be ‘turn on back porch light for 5 minutes if the garage door is opened’, then I’ll work on fine tuning (eventual goal is to make sure the porch light is on when i come home so I can see my keys at the back door)