Hoping someone can lend me a hand here.
Im still coming to grips with templating.
Im trying to turn on a light or a switch(fan) depending on the state of a couple input_selects.
If I enable the automation & script in my config files, HASS dumps out a huge error when I run Check Config.
Here is the Automation
alias: Motion Kitchen Lights
trigger:
platform: state
entity_id: binary_sensor.centralite_3326l_05989fde_1
to: 'on'
action:
service: script.motion_kit.yaml
1 - doesnāt affect whether or not your config validates, but thereās no reason to run a script as the only action of an automation, just put the contents of the script as the action.
2 - we canāt help you fix the format of your code without being able to see your formatting. Please use a code block.
Thats odd I thought for sure I clicked the option to add it s a code block the first time.
Its been edited, should show correctly now.
Only reason I ran it as a script was I was not aware you can have an automation run two different types of entities. In this case a fan.XXX and a switch.xxx. I figured this would be one of the use cases for scripts.
If I can run it directly in the automation itself, Im open to it.
Testing configuration at /config
2018-02-25 02:58:57 INFO (MainThread) [homeassistant.setup] Setting up introduction
2018-02-25 02:58:57 INFO (MainThread) [homeassistant.setup] Setting up mqtt
2018-02-25 02:58:57 INFO (MainThread) [homeassistant.setup] Setup of domain introduction took 0.8 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up http
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up recorder
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain mqtt took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain http took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain recorder took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up system_log
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up websocket_api
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up api
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up history
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain system_log took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain websocket_api took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain api took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain history took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up frontend
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain frontend took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up map
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up input_boolean
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up sensor
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up zwave
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up input_select
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up binary_sensor
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up wink
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up nest
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up sun
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up scene
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up zha
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up discovery
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up updater
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up joaoapps_join
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up group
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up notify
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up zone
2018-02-25 02:58:58 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: invalid template (TemplateSyntaxError: Unexpected end of template. Jinja was looking for the following tags: 'elif' or 'else' or 'endif'. The innermost block that needs to be closed is 'if'.) for dictionary value @ data['action'][0]['data_template']['entity_id']. Got None. (See /config/configuration.yaml, line 92). Please check the docs at https://home-assistant.io/components/automation/
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain map took 0.8 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain input_boolean took 0.8 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain sensor took 0.5 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain zwave took 0.5 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain input_select took 0.5 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain binary_sensor took 0.4 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain wink took 0.4 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain nest took 0.4 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain sun took 0.4 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain scene took 0.3 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain zha took 0.3 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain discovery took 0.3 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain updater took 0.3 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain joaoapps_join took 0.2 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain group took 0.2 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain notify took 0.2 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain zone took 0.2 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up logbook
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up cloud
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up conversation
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up panel_iframe
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up tts
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up camera
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up config
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up google_assistant
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up mqtt_statestream
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain logbook took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain cloud took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain conversation took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain panel_iframe took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain tts took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up script
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up light
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up remote
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up switch
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up automation
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain camera took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain config took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setting up device_tracker
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain google_assistant took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain mqtt_statestream took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain script took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain light took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain remote took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain switch took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain automation took 0.0 seconds.
2018-02-25 02:58:58 INFO (MainThread) [homeassistant.setup] Setup of domain device_tracker took 0.0 seconds.
Failed config
automation:
- action: [source /config/automation/sunrise_outdoor_lights.yaml:6]
service: script.outdoor_off
alias: Sunrise, outdoor lights
trigger: [source /config/automation/sunrise_outdoor_lights.yaml:2]
platform: sun
event: sunrise
offset: +00:30:00
- action: [source /config/automation/sunset_outdoor_lights.yaml:6]
service: script.outdoor_on
alias: Sunset, outdoor lights
trigger: [source /config/automation/sunset_outdoor_lights.yaml:2]
platform: sun
event: sunset
offset: -00:30:00
- action: [source /config/automation/motion_lr.yaml:6]
entity_id: group.all_living_room_lights
service: group.turn_on
alias: Motion Livingroom Lights
trigger: [source /config/automation/motion_lr.yaml:2]
platform: state
entity_id: binary_sensor.centralite_3326l_0e29bfd8_1
to: on
- action: [source /config/automation/motion_dr.yaml:6]
entity_id: light.ge_12724_3way_dimmer_switch_level
service: light.turn_on
alias: Motion Dining Room Lights
trigger: [source /config/automation/motion_dr.yaml:2]
platform: state
entity_id: binary_sensor.centralite_3326l_0598986c_1
to: on
- action: [source /config/automation/motion_office.yaml:6]
entity_id: light.osram_lightify_a19_rgbw_00a68da9_3
service: light.turn_on
alias: Motion Office Lights
trigger: [source /config/automation/motion_office.yaml:2]
platform: state
entity_id: binary_sensor.centralite_3326l_059899ee_1
to: on
- action: [source /config/automation/motion_kit.yaml:6]
data_template: [source /config/automation/motion_kit.yaml:8]
entity_id: {% if is_state("input_select.house_override", "Sleep") %}
fan.ge_12730_fan_control_switch_levelh
{% if is_state("input_select.livingroom_override", "Movie") %}
fan.ge_12730_fan_control_switch_level
{% else %}
switch.ge_12722_onoff_relay_switch_switch
{% endif %}
service: homeassistant.turn_on
alias: Motion Kitchen Lights
trigger: [source /config/automation/motion_kit.yaml:2]
platform: state
entity_id: binary_sensor.centralite_3326l_05989fde_1
to: on
- action: [source /config/automation/motion_din.yaml:6]
entity_id: light.ge_12724_3way_dimmer_switch_level
service: light.turn_on
alias: Motion Dining Room Lights
trigger: [source /config/automation/motion_din.yaml:2]
platform: state
entity_id: binary_sensor.centralite_3326l_0598986c_1
to: on
- action: [source /config/automation/motion_hall.yaml:6]
entity_id: group.hallway_lights
service: group.turn_on
alias: Motion Hallway Lights
trigger: [source /config/automation/motion_hall.yaml:2]
platform: state
entity_id: binary_sensor.centralite_3326l_0598986c_1
to: on
- action: [source /config/automation/timer_lr.yaml:6]
service: script.outdoor_on
alias: Sunset, outdoor lights
trigger: [source /config/automation/timer_lr.yaml:2]
platform: sun
event: sunset
offset: -00:30:00
Successful config (partial)
automation:
- action: ?
- service: script.outdoor_off
alias: Sunrise, outdoor lights
hide_entity: False
trigger: ?
- platform: sun
event: sunrise
offset: 0:30:00
- action: ?
- service: script.outdoor_on
alias: Sunset, outdoor lights
hide_entity: False
trigger: ?
- platform: sun
event: sunset
offset: -1 day, 23:30:00
- action: ?
- entity_id: ?
- group.all_living_room_lights
service: group.turn_on
alias: Motion Livingroom Lights
hide_entity: False
trigger: ?
- platform: state
entity_id: ?
- binary_sensor.centralite_3326l_0e29bfd8_1
to: on
- action: ?
- entity_id: ?
- light.ge_12724_3way_dimmer_switch_level
service: light.turn_on
alias: Motion Dining Room Lights
hide_entity: False
trigger: ?
- platform: state
entity_id: ?
- binary_sensor.centralite_3326l_0598986c_1
to: on
- action: ?
- entity_id: ?
- light.osram_lightify_a19_rgbw_00a68da9_3
service: light.turn_on
alias: Motion Office Lights
hide_entity: False
trigger: ?
- platform: state
entity_id: ?
- binary_sensor.centralite_3326l_059899ee_1
to: on
- action: ?
- entity_id: ?
- light.ge_12724_3way_dimmer_switch_level
service: light.turn_on
alias: Motion Dining Room Lights
hide_entity: False
trigger: ?
- platform: state
entity_id: ?
- binary_sensor.centralite_3326l_0598986c_1
to: on
- action: ?
- entity_id: ?
- group.hallway_lights
service: group.turn_on
alias: Motion Hallway Lights
hide_entity: False
trigger: ?
- platform: state
entity_id: ?
- binary_sensor.centralite_3326l_0598986c_1
to: on
- action: ?
- service: script.outdoor_on
alias: Sunset, outdoor lights
hide_entity: False
trigger: ?
- platform: sun
event: sunset
offset: -1 day, 23:30:00
So first it checks the IF, and if that evaluates true you get that result, if it evaluates false it moves to the next one, so weāre then saying itās none of the above (else), but is it this (if), which is shortened to ELIF, which you can do as many of as you like. Then at the bottom we have ELSE where we are saying nothing above is true so do this instead.
And yes, homeassistant.turn_on is basically āturn onā no matter what domain.