I can't get this automation to work

Happy new year!

I’m relatively new to this software and I’m currently trying to get an automation working that should turn on a scene in the morning, but only in the presence of a certain phone.

- alias: 'Lighting up Livingroom'
  trigger:
    - platform: state
      entity_id: device_tracker.70700d106398
      state: 'home'
    - platform: sun
      event: 'sunrise'
      offset: '-0:30:00'

  condition: use_trigger_values

  action:
    service: scene.turn_on
    entity_id: scene.GoldenSun

Checking the config with this file included results in an error:

17-01-02 17:56:24 ERROR (MainThread) [homeassistant.bootstrap] Invalid config for [automation]: expected a dictionary @ data[‘condition’][0]. Got None. (See ?:?). Please check the docs at https://home-assistant.io/components/automation/
Failed config
automation:
- action: [source /home/pi/.homeassistant/includes/automation/wake_up_living.yaml:12]
entity_id: scene.GoldenSun
service: scene.turn_on
alias: Lighting up Livingroom
condition: use_trigger_values
trigger: [source /home/pi/.homeassistant/includes/automation/wake_up_living.yaml:2]
- platform: state
entity_id: device_tracker.70700d106398
state: home

I assume it’s something simple, maybe someone can point me to my stupid configuration error?

Cheers,
Florian

I haven’t tried out an automation like that just yet, however it would seem to me that the trigger should be the sunrise, with the condition being that the device is home. This way you aren’t triggering the automation everytime the device goes from (other state) to home. Maybe something like this:

- alias: 'Lighting up Livingroom'
  trigger:
    platform: sun
    event: 'sunrise'
    offset: '-0:30:00'
  condition:
    platform: state
    entity_id: device_tracker.70700d106398
    state: 'home'
  action:
    service: scene.turn_on
    entity_id: scene.GoldenSun

Hi Jeremy,

thanks for your reply!

Your suggestion was easy to implement, so I just switched the order:

- alias: 'Lighting up Livingroom'
  trigger:
    - platform: sun
      event: 'sunrise'
      offset: '-0:30:00'
    - platform: state
      entity_id: device_tracker.70700d106398
      state: 'home'

  condition: use_trigger_values

  action:
    service: scene.turn_on
    entity_id: scene.GoldenSun

I’m still getting the error, though:

pi@raspberrypi:~/.homeassistant/includes/automation $ hass --script check_config
Testing configuration at /home/pi/.homeassistant
17-01-02 22:27:02 ERROR (MainThread) [homeassistant.bootstrap] Invalid config for [automation]: expected a dictionary @ data[‘condition’][0]. Got None. (See ?:?). Please check the docs at https://home-assistant.io/components/automation/
Failed config
automation:
- action: [source /home/pi/.homeassistant/includes/automation/wake_up_living.yaml:12]

Thanks,
Florian

Sorry. I realised that I did not implement what you suggested - your suggestion was slightly different.

Now, I just tried this:

- alias: 'Lighting up Livingroom'
  trigger:
   platform: sun
   event: 'sunrise'
   offset: '-0:30:00'

  condition: 
    platform: state
    entity_id: device_tracker.70700d106398
    state: 'home'

  action:
    service: scene.turn_on
    entity_id: scene.GoldenSun

and this resulted in a different error:

pi@raspberrypi:~/.homeassistant/includes/automation $ hass --script check_config
Testing configuration at /home/pi/.homeassistant
17-01-02 23:08:42 ERROR (MainThread) [homeassistant.bootstrap] Invalid config for [automation]: [platform] is an invalid option for [automation]. Check: automation->condition->0->platform. (See ?:?). Please check the docs at https://home-assistant.io/components/automation/
Failed config
  automation: 
    - action: [source /home/pi/.homeassistant/includes/automation/wake_up_living.yaml:12]
        entity_id: scene.GoldenSun
        service: scene.turn_on
      alias: Lighting up Livingroom
      condition: [source /home/pi/.homeassistant/includes/automation/wake_up_living.yaml:7]
        platform: state
        entity_id: device_tracker.70700d106398
        state: home
      trigger: [source /home/pi/.homeassistant/includes/automation/wake_up_living.yaml:2]
        platform: sun
        event: sunrise
        offset: -0:30:00

Thanks,
Florian

Make sure you have 2 spaces after your trigger for the platform. In the code you pasted above, there is only one. Here’s an excerpt from one of my automations that is working. Note that I have 2 triggers, one being a startup of HASS. The other thing is that my conditions are set such that the light will not turn on if I restart HASS after 11:00 pm.:

alias: "Porch Lights On At Sunset"
trigger:
  - platform: sun
    event: sunset
    offset: "-00:30:00"
  - platform: event
    event_type: homeassistant_start
condition:
  condition: and
  conditions:
    - condition: sun
      after: sunset
      after_offset: "-00:30:00"
    - condition: time
      before: "23:00:00"
action:
  - service: homeassistant.turn_on
    entity_id: switch.ZAP3
  - service: notify.pushbullet
    data:
      message: "Porch Lights On"

Hope this helps.

At the risk of sounding obvious, do you have the sun component loaded in your configuration.yaml? It’s not “part” of HA and has to be configured/enabled like any other platform. If your configuration doesn’t have a line like this:

sun:

That might be the problem. A lot of people (including me when I started out) don’t realize that the sun component isn’t enabled in HA by default.

Thanks for your reply!

Yes, the sun component was enabled but good point.

I changed the configuration just now to

- alias: 'Lighting up Livingroom'
  trigger:
    platform: sun
    event: 'sunrise'
    offset: '-0:30:00'

  condition: 
    condition: state
    entity_id: device_tracker.70700d106398
    state: 'home'

  action:
    service: scene.turn_on
    entity_id: scene.GoldenSun

and this time I’m getting away with my hass config check, so it appears to work now, now I just need a sunrise to test and verify the automation :slight_smile:

Cheers,
Florian