home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.48k stars 30.7k forks source link

BUG: homeassistant.components.automation.sun configuration key error #1580

Closed lauraGgit closed 8 years ago

lauraGgit commented 8 years ago

Home Assistant release (hass --version): 0.15.0

Python release (python3 --version): Python 3.4.2

Component/platform: homeassistant.components.automation.sun

Description of problem: In copying the automation 2 script in the "Cookbook" I am receiving the following error ERROR (MainThread) [homeassistant.components.automation.sun] Missing if-condition configuration key before or after

Expected:

Problem-relevant configuration.yaml entries and steps to reproduce:

homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: [redacted]
  longitude: [redacted]
  # C for Celcius, F for Fahrenheit
  temperature_unit: F
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones => On East coast
  time_zone: [redacted]

# View all events in a logbook
logbook:

# Track the sun
sun:
...
automation:
  alias: 'Rainy Day'

  trigger:
       - platform: state
         entity_id: sensor.weather_precip
         state: 'rain'
       - platform: state
         entity_id: group.all_devices
         state: 'home'
       - platform: time
         after: '14:00'
         before: '23:00'

  condition: use_trigger_values

  action:
    service: switch.turn_on
    entity_id: switch.lamp

automation 2:
  alias: 'Rain is over'
  trigger:
       - platform: state
         entity_id: sensor.weather_precip
         state: 'None'
       - platform: sun
         event: 'sunset'
         offset: '-01:00:00'

  condition: use_trigger_values
  action:
    service: switch.turn_on
    entity_id: switch.lamp
  1. Since this switch is found via wemo, should i be using a different service?

Traceback (if applicable):

16-03-20 02:20:16 ERROR (MainThread) [homeassistant.components.automation.sun] Missing if-condition configuration key before or after
lauraGgit commented 8 years ago

this is not resolved with the addition of entity_id: sun.sun

froz commented 8 years ago

I fixed this in my automation by replacing -platform: sun with a numeric_state:

- platform: numeric_state entity_id: sun.sun value_template: '{{ state.attributes.elevation }}' above: 5

I used the elevation numeric_state to avoid an overlap with my regular sunset trigger, which also uses the elevation rather than a sunset offset. Plus, I am unsure how one would specify the offset as a state or numeric_state.

Also, I believe you need to use homeassistant as the service rather than switch, and assuming you are turning the lamp off when 'Rain is over', homeassistant.turn_off

lauraGgit commented 8 years ago

This seems to have worked.