I have this in my config.yaml
sensor: !include sensors.yaml
And this in my sensors.yaml file
- platform: template
sensors:
alarm_arm_status:
value_template: >-
{% if states.binary_sensor.alarm_arm_status.state == 'off' %}
Disarmed
{% elif states.binary_sensor.alarm_arm_status.state == 'on' %}
Armed
icon_template: >
{% if states.binary_sensor.alarm_arm_status.state == 'off' %}
mdi:lock-open
{% elif states.binary_sensor.alarm_arm_status.state == 'on' %}
mdi:lock
I keep getting error:
Configuration invalid
Error loading /config/configuration.yaml: mapping values are not allowed here
in "/config/sensors.yaml", line 2, column 14
What is the correct way to update that sensor, Iām sure my syntax is wrong
tom_l
August 31, 2019, 12:33am
2
{% endif %}
required in two places. You should specify an entity id to monitor for the template to update. Also you should capture the unknown state and use this form of template to avoid errors at start up:
- platform: template
sensors:
alarm_arm_status:
entity_id: binary_sensor.alarm_arm_status
value_template: >-
{% if is_state('binary_sensor.alarm_arm_status', 'off') %}
Disarmed
{% elif is_state('binary_sensor.alarm_arm_status', 'on') %}
Armed
{% else %}
Unknown
{% endif %}
icon_template: >
{% if is_state('binary_sensor.alarm_arm_status', 'off') %}
mdi:lock-open
{% elif is_state('binary_sensor.alarm_arm_status', 'on') %}
mdi:lock
{% else %}
mdi:lock-alert
{% endif %}
finity
August 31, 2019, 2:12am
3
Also, check the indentation for everything after the first line. It all needs moved back to the left 4 spaces in your first post and 2 spaces in toms post.
1 Like
Thanks, I believe I have it right but again the same error
Seems to be because of this guy:
Is the indentation still wrong? Looks good in VS code
tom_l
August 31, 2019, 7:57am
5
sensors:
should be at the same indentation level as platform:
Sorry. I copied your error.
Should be:
- platform: template
sensors:
alarm_arm_status:
entity_id: binary_sensor.alarm_arm_status
value_template: >-
{% if is_state('binary_sensor.alarm_arm_status', 'off') %}
Disarmed
{% elif is_state('binary_sensor.alarm_arm_status', 'on') %}
Armed
{% else %}
Unknown
{% endif %}
icon_template: >
{% if is_state('binary_sensor.alarm_arm_status', 'off') %}
mdi:lock-open
{% elif is_state('binary_sensor.alarm_arm_status', 'on') %}
mdi:lock
{% else %}
mdi:lock-alert
{% endif %}
āmapping values not allowed hereā is nearly always an indentation problem.
But it looks like the icon part worked ok but the value did not, still showing Open/Closed
I assumed the Open above should be changed with Armed?
tom_l
August 31, 2019, 8:18am
8
The icon is not correct either. Thatās a shield not a lock.
Are you sure you have the correct sensor?
It should be: sensor.alarm_arm_status
I forgot I have this in my customize.yaml
binary_sensor.alarm_arm_status:
icon: mdi:shield-check
But yeah I remove that and the icon does not work either
And yeah the name looks good
tom_l
August 31, 2019, 8:38am
10
No, it does not.
sensor.alarm_arm_status
not
binary_sensor.alarm_arm_status
Still no joy
- platform: template
sensors:
alarm_arm_status:
entity_id: sensor.alarm_arm_status
value_template: >-
{% if is_state('sensor.alarm_arm_status', 'off') %}
Disarmed
{% elif is_state('sensor.alarm_arm_status', 'on') %}
Armed
{% else %}
Unknown
{% endif %}
icon_template: >-
{% if is_state('sensor.alarm_arm_status', 'off') %}
mdi:lock-open
{% elif is_state('sensor.alarm_arm_status', 'on') %}
mdi:lock
{% else %}
mdi:lock-alert
{% endif %}
Sure it is not with the binary in front like in the card?
tom_l
August 31, 2019, 9:03am
12
No, no, no.
Donāt change the sensor template. Put that back to using the binary sensor.
Then put this in an entities card in the front end:
sensor.alarm_arm_status
not
binary_sensor.alarm_arm_status
You made a template sensor not a template binary sensor .
Sorry, getting confused thought the template was just being applied to the binary sensor and not creating a new one, however I cannot find the new one in the entity list
- platform: template
sensors:
alarm_arm_status:
entity_id: sensor.alarm_arm_status
value_template: >-
{% if is_state('binary_sensor.alarm_arm_status', 'off') %}
Disarmed
{% elif is_state('binary_sensor.alarm_arm_status', 'on') %}
Armed
{% else %}
Unknown
{% endif %}
icon_template: >-
{% if is_state('binary_sensor.alarm_arm_status', 'off') %}
mdi:lock-open
{% elif is_state('binary_sensor.alarm_arm_status', 'on') %}
mdi:lock
{% else %}
mdi:lock-alert
{% endif %}
I appreciate the help, I think Iām making this harder than it is
tom_l
August 31, 2019, 10:13am
14
You missed one
- platform: template
sensors:
alarm_arm_status:
entity_id: binary_sensor.alarm_arm_status #### <-----HERE
value_template: >-
{% if is_state('binary_sensor.alarm_arm_status', 'off') %}
Disarmed
{% elif is_state('binary_sensor.alarm_arm_status', 'on') %}
Armed
{% else %}
Unknown
{% endif %}
icon_template: >-
{% if is_state('binary_sensor.alarm_arm_status', 'off') %}
mdi:lock-open
{% elif is_state('binary_sensor.alarm_arm_status', 'on') %}
mdi:lock
{% else %}
mdi:lock-alert
{% endif %}
All of this should be in your sensors.yaml
file. Not binary_sensors.yaml
Tried that too and same but I reckon my config.yaml is the issue
At the top:
And I found this later on
I am guessing it is totally ignoring my sensors file because of the other sensor mention? Going to try and put all of them in the file and see if it fixes it
tom_l
August 31, 2019, 10:18am
16
Thatās bad.
Move all the config below that sensors:
(minus sensors:
, delete that) to your sensors.yaml file.
you should only have one sensors:
in your configuration.yaml file and thatās the one pointing to sensors.yaml.
Yeah I was expecting the usual error cannot have multiple sensors etc
Tried the most basic example from https://www.home-assistant.io/components/template/ and just cannot get past the indentation error I think
my sensors.yaml file currently
- platform: template
sensors:
- solar_angle:
friendly_name: "Sun angle"
unit_of_measurement: 'degrees'
value_template: "{{ state_attr('sun.sun', 'elevation') }}"
config.yaml
And same error
I know that this works fine directly in config.yaml since I can see the new sun sensor in the entity list
sensor:
- platform: template
sensors:
solar_angle:
friendly_name: "Sun angle"
unit_of_measurement: 'degrees'
value_template: "{{ state_attr('sun.sun', 'elevation') }}"
tom_l
August 31, 2019, 12:43pm
18
The two sensor configs you posted are different.
This is wrong:
- platform: template
sensors: ##### <----- you indented this again.
- solar_angle: ################ <-- remove the dash, fix the indentation
friendly_name: "Sun angle"
unit_of_measurement: 'degrees'
value_template: "{{ state_attr('sun.sun', 'elevation') }}"
This is right:
- platform: template
sensors:
solar_angle:
friendly_name: "Sun angle"
unit_of_measurement: 'degrees'
value_template: "{{ state_attr('sun.sun', 'elevation') }}"
Thereās two types of multiple item objects. Lists, that use ā-ā and maps that dont.
Template sensors are maps, not lists. See the ā(map)ā in the documentation, https://www.home-assistant.io/components/template/#sensors
Worked it out thanks, it was a combination of - and the sensors: under - platform that was not indented properly. Never thought Iād say it but I think I prefer JSON
One more question, the status of the new sensor.alarm_arm_status
doesnāt seem to be instantly updated when the state of binary_sensor.alarm_arm_status
changes. Any idea why?