really hoping someone can help me out. I think I am on the right path to accomplishing dynamic icons based off a sensor input. At a high level I have a sensor for a garage door. It uses http GET command to retrieve a message “OPEN” or “CLOSED”. real simple. My sensors are working correctly and HA shows the correct status. I am following Bruh’s config on GIT hub where I have separate YAML files stored in ./sensors.
My error is invalid.config “sensor.template” Check config in the UI states…
so…
.homeassistant/configuration.yaml
.homeassistant/sensors/garage_1.yaml
.homeassistant/sensors/garage_2.yaml
.homeassistant/sensors/template_sensors/garage_1_template.yaml
.homeassistant/sensors/template_sensors/garage_2_template.yaml
so far so good I think
…Garage_1.yaml contains…
platform: rest
resource: http://192.168.1.180/device/Garage1status
method: GET
name: Garage Door 1 Status
like this?
value_template: ‘{{ is_state.sensor.garage_door_2_status.state }}’
I get the same error for both Garage 1 and Garage 2
the formatting has me a bit confused though. Unfortunately the forum isn’t preserving the spacing eventhough I used the </> button. Anyhow for each garage_X_template.yaml file the first line has 2 spaces. then line 2 is sensors lined up with platform IE:
platform: template
sensors:
Garage_2_template:
value_template
icon_template
Here’s what I have in garage_2_template.yaml
more logging…
2017-06-07 17:30:10 INFO (MainThread) [homeassistant.setup] Setting up automation
2017-06-07 17:30:10 ERROR (MainThread) [homeassistant.config] Invalid config for [sensor.template]: [Garage_2_template] is an invalid option for [sensor.template]. Check: sensor.template->sensors->Garage_2_template. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/
2017-06-07 17:30:10 ERROR (MainThread) [homeassistant.config] Invalid config for [sensor.template]: [Garage_1_template] is an invalid option for [sensor.template]. Check: sensor.template->sensors->Garage_1_template. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/
2017-06-07 17:30:10 INFO (MainThread) [homeassistant.setup] Setting up sensor
2017-06-07 17:30:10 INFO (MainThread) [homeassistant.setup] Setting up discovery
2017-06-07 17:30:10 INFO (MainThread) [homeassistant.setup] Setting up light
2017-06-07 17:30:10 INFO (MainThread) [homeassistant.setup] Setting up logbook
2017-06-07 17:30:10 INFO (MainThread) [homeassistant.setup] Setting up config
2017-06-07 17:30:10 INFO (MainThread) [homeassistant.setup] Setting up tts
Failed config
sensor.template:
platform: template
sensors: [source /home/jtroberts/.homeassistant/sensors/template_sensors/garage_1_template.yaml:3]
Garage_1_template: [source /home/jtroberts/.homeassistant/sensors/template_sensors/garage_1_template.yaml:4]
icon_template: {% if is_state(“sensor.garage_door_1_status”, “OPEN”) %}mdi:amazon{% else %}mdi:android{% endif %}
value_template: {{ is_state.sensor.garage_door_2_status.state }}
If I take my value_template and icon_template and put them individually into the developertools I get the correct results. That is OPEN or CLOSED and either ‘mdi:android’ or ‘mdi:amazon’
OK, we’re getting somewhere. For others to see here’s what I have in my garage_2_template.yaml
# Garage Door 2
platform: template
sensors:
garage_2_status:
value_template: '{{ states.sensor.garage_door_2_status.state }}'
icon_template: '{% if is_state("sensor.garage_door_2_status", "OPEN") %}mdi:amazon{% else %}mdi:android{% endif %}'
friendly_name: "Garage 2 Status"
That is working but I do not have the dynamic icons. any ideas?
here's what the developer tools show
That is exactly what I want to see. Well I assume so. Is sensor.garage_2_status “icon: mdi:android” a string or an actual icon. not sure. More importantly in the UI I do not get the amazon or android icons based on status. thoughts?
Am I on the right path? PS: I do have a customize.yaml. Here are it’s contents.
switch.garage_door_1:
friendly_name: Garage Door 1
icon: mdi:garage
switch.garage_door_2:
icon: mdi:garage
friendly_name: Garage Door 2
sensor.garage_1_status:
friendly_name: Garage Door 1 Status
sensor.garage_2_status:
friendly_name: Garage Door 2 Status
Appreciate the help. thx
That throws this error…
2017-06-08 11:29:51 ERROR (MainThread) [homeassistant.bootstrap] Error loading /home/jtroberts/.homeassistant/configuration.yaml: while scanning for the next token
found character ‘%’ that cannot start any token
in “/home/jtroberts/.homeassistant/sensors/template_sensors/garage_2_template.yaml”, line 6, column 23
And the only difference apart for the fact mine are on different lines is the value_template is enclosed with double quotes and it uses the states() statement, tho’ I’m not sure why that would affect the icon :P.
wow… good stuff. Unfortunately the devil is in the details. In my groups.yaml my entity wasn’t “garage_2_status”. So I never asked the UI to show the new icon. rookie mistake I guess. good new is both methods work. details below for others.
Configuration.yaml (see above) didn’t change but pay close attention to the last line where I load my sensor files.
customize.yaml
switch.garage_door_1:
friendly_name: Garage Door 1
icon: mdi:garage
switch.garage_door_2:
icon: mdi:garage
friendly_name: Garage Door 2
sensor.garage_1_status:
friendly_name: Garage Door 1 Status
sensor.garage_2_status:
friendly_name: Garage Door 2 Status
@jtroberts Thank you for posting your final code, that was really helpful. The part that was throwing me for a loop, is that I didn’t realize that templates create a completely new and separate sensor. (Am I understanding that right?) With the config above, in your states tab, you should have both: sensor.garage_door_1_status sensor.garage_1_status
Looking at the front end created with groups.yaml, we will only see sensor.garage_1_status, while sensor.garage_door_1_status is not displayed at all, is that correct?