Here and there I am confronted with the HASS script script_check (hass --script check_config) not detecting errors in my yaml-files. The errors show up in the “invalid config” card and I have to debug by checking the logs…
The suspicious line in my configuration.yaml looks like:
#include some automations
automation: !include automations.yaml
Access rigths to the automations.yaml are ok.
PS: I am aware of HASS packages (https://home-assistant.io/topics/packages/) but had no time to implement this new feature in my configs… And I have to admit I don’t understand this new concept at the first glance… I’ll have to read more about this.
I actually used the formatting button… But it didn’t change the format. Ha no line break bevor the code block or something like this. Changed it in my post.
Here is my automation.yaml:
- alias: "light if motion"
trigger:
platform: state
entity_id: binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_14_0
to: 'on'
action:
- service: switch.turn_on
data:
entity_id: switch.fibaro_system_fgs223_double_relay_switch_28_0
- alias: "turn off stair ligth after 10 minutes without motion"
trigger:
platform: template
value_template: "{{ as_timestamp(now()) - as_timestamp(states.binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_14_0.last_changed) > 600 }}"
action:
- service: switch.turn_off
data:
entity_id: switch.fibaro_system_fgs223_double_relay_switch_28_0
- alias: "light trigger in the night"
trigger:
platform: numeric_state
entity_id: sensor.fibaro_system_fgms001_motion_sensor_luminance_24_3
below: 1
action:
- condition: time
after: '23:00:00'
- condition: time
before: '07:00:00'
- condition: state
entity_id: 'switch.cinema_mode'
state: 'off'
- condition: state
entity_id: 'light.livingone'
state: 'off'
- service: light.turn_on
data:
entity_id: light.livingone
- condition: state
entity_id: 'light.livingtwo'
state: 'off'
- service: light.turn_on
data:
entity_id: light.livingtwo
- alias: "security camera 1 motion trigger"
trigger:
platform: template
value_template: '{{states.camera.security_cam_entrance.attributes.change > 0 }}'
action:
- service: light.turn_on
data:
entity_id: light.ugbureau
brightness: 255
# color_name: red
flash: short
- service: light.turn_on
data:
entity_id: light.ugdiele
brightness: 255
# color_name: red
flash: short
- service: light.turn_on
data:
entity_id: light.ugschlafzimmer
brightness: 255
# color_name: red
flash: short
- alias: "flash if petpointer daemon delivered battery state is low"
trigger:
platform: numeric_state
entity_id: petpointer.battery_state
below: 20
action:
- condition: template
value_template: '{{(as_timestamp(now())-as_timestamp(states.petpointer.battery_state.last_updated)) > 1800 }}'
- service: light.turn_on
data:
entity_id: light.livingone
brightness: 255
# color_name: red
flash: long
- alias: "Flash petpointer alarm on motion in living room"
trigger:
platform: state
entity_id: binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_24_0
to: 'on'
action:
- condition: numeric_state
entity_id: petpointer.battery_state
below: 20
- condition: template
value_template: '{{(as_timestamp(now())-as_timestamp(states.petpointer.battery_state.last_updated)) > 1800 }}'
- service: light.turn_on
data:
entity_id: light.livingone
brightness: 255
color_name: red
flash: long
- alias: "Open shutters at sunrise downstairs"
trigger:
platform: sun
event: sunrise
offset: "-00:30:00"
action:
- service: cover.open_cover
data:
# diele shutter
entity_id: cover.fibaro_system_fgrm222_roller_shutter_controller_2_level_3_0
- service: cover.open_cover
data:
#schlafzimmer shutter
entity_id: cover.fibaro_system_fgrm222_roller_shutter_controller_2_level_15_0
- alias: "Open shutters in the morning if motion detected"
trigger:
platform: state
entity_id: binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_24_0
to: 'on'
condition:
conditions:
- condition: template
value_template: '{{ states.cover.fibaro_system_fgrm222_roller_shutter_controller_2_level_21_0.attributes.current_position < 95 }}'
- condition: sun
after: sunrise
- condition: sun
before: sunset
action:
- service: homeassistant.turn_on
entity_id: script.shutter_living_up
My indentations are the most beautiful (I’m editing with vim over ssh on mi pi) but should work. The last automation was altered according to your and other’s help here (question about conditions).
I debugged the last automation above to to the one below and now it loads without a problem. Problem was not detected by the check_config script. Output was nothing more than:
root@homeautomation:~# hass --script check_config
Testing configuration at /root/.homeassistant
root@homeautomation:~#
The working automation looks like this:
- alias: "Open shutters in the morning if motion detected"
trigger:
platform: state
entity_id: binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_24_0
to: 'on'
condition:
condition: and
conditions:
- condition: template
value_template: '{{ states.cover.fibaro_system_fgrm222_roller_shutter_controller_2_level_21_0.attributes.current_position < 95 }}'
- condition: sun
after: sunrise
- condition: sun
before: sunset
action:
- service: homeassistant.turn_on
entity_id: script.shutter_living_up
- alias: "light if motion"
trigger:
platform: state
entity_id: binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_14_0
to: 'on'
action:
- service: switch.turn_on
data:
entity_id: switch.fibaro_system_fgs223_double_relay_switch_28_0
- alias: "turn off stair ligth after 10 minutes without motion"
trigger:
platform: template
value_template: "{{ as_timestamp(now()) - as_timestamp(states.binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_14_0.last_changed) > 600 }}"
action:
- service: switch.turn_off
data:
entity_id: switch.fibaro_system_fgs223_double_relay_switch_28_0
- alias: "light trigger in the night"
trigger:
platform: numeric_state
entity_id: sensor.fibaro_system_fgms001_motion_sensor_luminance_24_3
below: 1
condition:
conditions: and
- condition: time
after: '23:00:00'
- condition: time
before: '07:00:00'
- condition: state
entity_id: 'switch.cinema_mode'
state: 'off'
- condition: state
entity_id: 'light.livingone'
state: 'off'
action:
- service: light.turn_on
data:
entity_id: light.livingone
- condition: state
entity_id: 'light.livingtwo'
state: 'off'
- service: light.turn_on
data:
entity_id: light.livingtwo
- alias: "security camera 1 motion trigger"
trigger:
platform: template
value_template: '{{states.camera.security_cam_entrance.attributes.change > 0 }}'
action:
- service: light.turn_on
data:
entity_id: light.ugbureau
brightness: 255
# color_name: red
flash: short
- service: light.turn_on
data:
entity_id: light.ugdiele
brightness: 255
# color_name: red
flash: short
- service: light.turn_on
data:
entity_id: light.ugschlafzimmer
brightness: 255
# color_name: red
flash: short
- alias: "petpointer_low_battery"
trigger:
platform: state
entity_id: binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_24_0
to: 'on'
condition:
conditions: and
- condition: numeric_state
entity_id: petpointer.battery_state
below: 20
- condition: template
value_template: '{{(as_timestamp(now())-as_timestamp(states.petpointer.battery_state.last_updated)) > 1800 }}'
action:
- service: light.turn_on
data:
entity_id: light.livingone
brightness: 255
color_name: red
flash: long
- service: automation.turn_off
entity_id: automation.petpointer_low_battery
- delay: 01:00:00
- service: automation.turn_on
entity_id: automation.petpointer_low_battery
- alias: "Open shutters at sunrise downstairs"
trigger:
platform: sun
event: sunrise
offset: "-00:30:00"
action:
- service: cover.open_cover
data:
# diele shutter
entity_id: cover.fibaro_system_fgrm222_roller_shutter_controller_2_level_3_0
- service: cover.open_cover
data:
#schlafzimmer shutter
entity_id: cover.fibaro_system_fgrm222_roller_shutter_controller_2_level_15_0
#Open shutters in the morning if motion detected
- alias: "a_shutter_1"
trigger:
platform: state
entity_id: binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_24_0
to: 'on'
condition:
condition: and
conditions:
- condition: template
value_template: '{{ states.cover.fibaro_system_fgrm222_roller_shutter_controller_2_level_21_0.attributes.current_position < 95 }}'
- condition: time
after: "06:30:00"
- condition: time
before: "20:35:00"
action:
- service: homeassistant.turn_on
entity_id: script.shutter_living_up
- service: automation.turn_off
entity_id: automation.a_shutter_1
- delay: 00:01:00
- service: automation.turn_on
entity_id: automation.a_shutter_1
Output of hass --script check_config:
root@homeautomation:~# hass --script check_config
Testing configuration at /root/.homeassistant
I reloaded the automations in service tab with HASS running. No output in the “Invalid Config” card or even in the logs. I restartet HASS and look whats in the logs:
Jan 30 20:29:42 homeautomation hass[1745]: Config directory: /home/pi/.homeassistant
Jan 30 20:29:45 homeautomation systemd[1]: Starting Home Assistant...
Jan 30 20:29:45 homeautomation systemd[1]: Started Home Assistant.
Jan 30 20:29:59 homeautomation hass[23496]: #033[31m17-01-30 20:29:59 ERROR (Thread-1) homeassistant.util.yaml] mapping values are not allowed here
Jan 30 20:29:59 homeautomation hass[23496]: in "/home/pi/.homeassistant/automations.yaml", line 28, column 16#033[0m
Jan 30 20:29:59 homeautomation hass[23496]: Config directory: /home/pi/.homeassistant
I’ve found the best way to validate is with Atom editor with yamllint enabled. It does a much better job at pointing out errors than notepad++ or winSCP