I need a flag to change the icon color for a custom button. If state.water_heater.snst081556q_oven and sensor.snst081556q_cook_mode both equal off, the stove is all off. I am getting the below errors in-spite of the fact in the editor I get the green check-mark. Help appreciated, thanks in advance, Anthony Baker
- sensor:
- name: 'StoveOff'
state: >
"{% is_state('state.water_heater.snst081556q_oven', 'Off') and is_state('sensor.snst081556q_cook_mode', 'Off') %}"
Logger: homeassistant.config
Source: config.py:357
First occurred: 4:17:02 PM (19 occurrences)
Last logged: 6:58:52 PM
Invalid config for 'template' at templates.yaml, line 24: required key 'state' not provided Invalid config for 'template' at templates.yaml, line 25: 'state' is an invalid option for 'template', check: state
Invalid config for 'template' at templates.yaml, line 25: invalid template (TemplateSyntaxError: Encountered unknown tag 'is_state'.) for dictionary value 'sensor->0->state', got "{% is_state('state.water_heater.snst081556q_oven', 'Off') and is_state('sensor.snst081556q_cook_mode', 'Off') %}\n"
Invalid config for 'template' at templates.yaml, line 24: invalid template (TemplateSyntaxError: Encountered unknown tag 'is_state'.) for dictionary value 'sensor->1->state', got "{% is_state('state.water_heater.snst081556q_oven', 'Off') and is_state('sensor.snst081556q_cook_mode', 'Off') %}\n"
Invalid config for 'template' at templates.yaml, line 24: invalid template (TemplateSyntaxError: Encountered unknown tag 'is_state'.) for dictionary value 'sensor->1->state', got "{% is_state('water_heater.snst081556q_oven', 'Off') and is_state('sensor.snst081556q_cook_mode', 'Off') %}\n"
Invalid config for 'template' at templates.yaml, line 25: invalid template (TemplateSyntaxError: Encountered unknown tag 'is_state'.) for dictionary value 'binary_sensor->0->state', got "{% is_state('state.water_heater.snst081556q_oven', 'Off') and is_state('sensor.snst081556q_cook_mode', 'Off') %}\n"
- sensors:
time_templated:
# value_template: "{{ now().strftime('%X') }}"
value_template: "{{ now().strftime('%H:%M:%S') }}"
friendly_name: ''
icon_template: 'mdi:clock'
date_templated:
value_template: "{{ now().strftime('%d %B, %Y') }}"
friendly_name: ''
icon_template: 'mdi:clock'
weekday_templated:
value_template: "{{ now().strftime('%A') }}"
friendly_name: ''
icon_template: 'mdi:clock'
- sensor:
- name: 'Lights On'
icon: mdi:lightbulb-group-on
state: "{{ states.light
| rejectattr('entity_id', 'in', ['light.master_bedroom_ceiling_fan', 'light.reolink_video_doorbell_wifi_infra_red_lights_in_night_mode'])
| selectattr('state', 'eq', 'on')| list | count + states.input_boolean
| selectattr('state', 'eq', 'on') | list | count}}"
- sensor:
- name: 'StoveOff'
state: >
"{% is_state('state.water_heater.snst081556q_oven', 'Off') and is_state('sensor.snst081556q_cook_mode', 'Off') %}"
- sensor:
##### Low Battery list ##################################
- name: "Low Battery Devices"
unique_id: ba292875-ae67-480d-9867-29cdb20afaea
icon: >
mdi:battery-low
state: >
{% set threshold = states('input_number.battery_threshold') | int %}
{%- set ns = namespace(sensors=[]) -%}
{%- for state in states.sensor
| selectattr('attributes.device_class', 'defined')
| selectattr('attributes.state_class', 'defined')
| selectattr('attributes.device_class', '==', 'battery')
| selectattr('attributes.state_class', '==', 'measurement')
| selectattr('state', 'is_number') -%}
{%- if state.state | int <= threshold -%}
{% set ns.sensors = ns.sensors + [dict(name = state.name | replace(' battery', '') | replace(' Battery', ''), state = state.state | int)] %}
{%- endif -%}
{%- endfor -%}
{%- set batt = ns.sensors | sort(attribute='state') %}
{%- set ns = namespace(batt='') -%}
{%- for state in batt -%}
{% set ns.batt= ns.batt + (state.name ~ ' (' ~ state.state ~'%)' ~ "\n") %}
{%- endfor -%}
{% if ns.batt | count > 0 %}
{{ ns.batt | truncate(255, true, '...') }}
{% else %}
{{ 'unavailable' }}
{% endif %}
##----------------------------------------------------------------------------------------------------------------------
##
## Unavailable Devices Sensor
##
## 05-Feb-2024 | Andy Symons | created
## 16-May-2024 | mr_roboto | updated to track unavailable device count rather than entities
##
## Credit: based loosely on https://github.com/jazzyisj/unavailable-entities-sensor/blob/main/README.md
##
## The sensor provides lists related to real devices, not internal entities, helpers, automations etc.,
## Entities with state 'unknown' are not counted, because it is possible for a device to have a sub-entity that is
## unknown while the device itself is available.
##
## The STATE simply gives the count of unavailable entities.
## The long results have to be attributes because the state cannot contain more than 255 characters:
## ATTRIBUTE 'entity_id_list' contains a list of unavailable entities using their entity ids, which may or may not have been set by the user.
## ATTRIBUTE 'entity_name_list' contains a list of unavailable entities using their friendly names as assigned by the user.
## ATTRIBUTE 'device_name_list contains a list of the devices that are unavailable, which is to say having one or more entities that are unavailable,
## using their friendly names as assigned by the user.
##
##----------------------------------------------------------------------------------------------------------------------
- sensor:
name: "Unavailable Devices"
unique_id: unavailable_devices
icon: "{{ iif(states(this.entity_id)|int(-1) > 0,'mdi:alert-circle','mdi:check-circle') }}"
state_class: measurement
unit_of_measurement: devices
# The entity state is the count of unavailable devices.
state: >
{{ states
| selectattr('domain','in',['binary_sensor', 'climate', 'light', 'sensor', 'switch'])
| selectattr('state', 'in', ['unavailable'])
| map(attribute='entity_id')
| map('device_attr', 'name_by_user')
| reject('match', 'None')
| unique
| list
| count
}}
# The long results have to be attributes because the state cannot contain more than 255 characters.
attributes:
## A list of the devices that are unavailable, using their friendly names as assigned by the user.
device_name_list: >-
{{ states
| selectattr('domain','in',['binary_sensor', 'climate', 'light', 'sensor', 'switch'])
| selectattr('state', 'in', ['unavailable'])
| map(attribute='entity_id')
| map('device_attr', 'name_by_user')
| reject('match', 'None')
| unique
| list
| sort
| join('\n')
}}
## A list of unavailable entities using their friendly names as assigned by the user.
entity_name_list: >-
{{ states
| selectattr('domain','in',['binary_sensor', 'climate', 'light', 'sensor', 'switch'])
| selectattr('state', 'in', ['unavailable'])
| map(attribute='entity_id')
| map('state_attr', 'friendly_name')
| reject('match', 'None')
| list
| sort
| join('\n')
}}
## A list of unavailable entities using their entity ids (which may or may not have been set by the user).
entity_id_list: >-
{{ states
| selectattr('domain','in',['binary_sensor', 'climate', 'light', 'sensor', 'switch'])
| selectattr('state', 'in', ['unavailable'])
| map(attribute='entity_id')
| reject('match', 'None')
| list
| sort
| join('\n')
}}
# HOW THE ATTRIBUTE TEMPLATES WORK
# -- Taking device_name_list as an example...
#
# {{ states -- all the states (entities) in the system
# | selectattr('domain','in',['binary_sensor', 'climate', etc. -- filter only the entities for real devices
# | selectattr('state', 'in', ['unavailable']) -- filter only entities that are unavailable
# | map(attribute='entity_id') -- get the entity id from the record
# | map('device_attr', 'name_by_user') -- map the entity id onto the device name
# | reject('match', 'None') -- take out names 'None' (meaning there is no name, so not a device)
# | unique -- take out duplicates (devices usually have several entities)
# | list -- make into a list (in the template sense)
# | sort -- put them in alphabetical order
# | join('\n') -- take out extraneous punctuation for a tidy output
# }}
2 posts - 2 participants
Read full topic