i get this error in the logs… its complaining about the value? just not sure how u fix that
not sure where to look?
Logger: homeassistant.helpers.event
Source: components/sensor/__init__.py:595
First occurred: 12:15:00 PM (1 occurrences)
Last logged: 12:15:00 PM
Error while dispatching event for switch.h_sauna_pump to <Job track state_changed event {'switch.tp_link_smart_plug_1799_window_well_pump', 'switch.h_sauna_pump', 'group.pumps'} HassJobType.Callback <bound method TrackTemplateResultInfo._refresh of <TrackTemplateResultInfo {Template<template=({% if states('group.pumps') == 'on' %} {%- for item in states.group.pumps.attributes.entity_id if states(item) == "on" %} {% if loop.last %} {{loop.index}} {% endif %} {% endfor %} {% else %} 0 {% endif %}) renders=8>: <RenderInfo Template<template=({% if states('group.pumps') == 'on' %} {%- for item in states.group.pumps.attributes.entity_id if states(item) == "on" %} {% if loop.last %} {{loop.index}} {% endif %} {% endfor %} {% else %} 0 {% endif %}) renders=8> all_states=False all_states_lifecycle=False domains=frozenset() domains_lifecycle=frozenset() entities=frozenset({'switch.tp_link_smart_plug_1799_window_well_pump', 'switch.h_sauna_pump', 'group.pumps'}) rate_limit=None has_time=False exception=None is_static=False>}>>>
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 591, in state
numerical_value = int(value)
^^^^^^^^^^
ValueError: invalid literal for int() with base 10: ''
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 289, in _async_dispatch_entity_id_event
hass.async_run_hass_job(job, event)
File "/usr/src/homeassistant/homeassistant/core.py", line 625, in async_run_hass_job
hassjob.target(*args)
File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1202, in _refresh
self.hass.async_run_hass_job(self._job, event, updates)
File "/usr/src/homeassistant/homeassistant/core.py", line 625, in async_run_hass_job
hassjob.target(*args)
File "/usr/src/homeassistant/homeassistant/helpers/template_entity.py", line 366, in _handle_results
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 746, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 808, in _async_write_ha_state
state = self._stringify_state(available)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 752, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 595, in state
raise ValueError(
ValueError: Sensor sensor.pumps_on has device class 'None', state class 'None' unit 'Pumps On' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '' (<class 'str'>)
Is sensor.pumps_on a Template Sensor you created?
If it is, remove this line from its configuration:
unit_of_measurement: 'Pumps On'
When you use that option, the Template Sensor’s value must always be numeric. However, according to the last line of the error message, your Template Sensor’s reported a non-numeric value (an empty string) and that’s invalid.
ValueError: Sensor sensor.pumps_on has device class ‘None’, state class ‘None’ unit ‘Pumps On’ and suggested precision ‘None’ thus indicating it has a numeric value; however, it has the non-numeric value: ‘’ (<class ‘str’>)
Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.
It should actually return a number, so a unit is valid. It’s just another case of needing an availability template. It can also be done without iterating.
I agree. Unfortunately, according to the error message, there was at least one occasion when it reported an empty string (not sure how but there it is). In this case, it seemed easier to remove unit_of_measurement than add availability_template. Nevertheless you’re right and, for completeness, this is one way to do it:
availability_template: "{{ state_attr('group.pumps', 'entity_id') is not none }}"
You can try this version but if you ever get the same error message, that this sensor’s value is non-numeric, then remove the unit_of_measurement option.
pumps_on:
friendly_name: "Pumps On"
unit_of_measurement: "Pumps On"
value_template: >-
{{ expand(state_attr('group.pumps', 'entity_id'))
| selectattr('state', 'eq', 'on') | list | count }}
availability_template: "{{ state_attr('group.pumps', 'entity_id') is not none }}"
EDIT
Correction. Forgot to include the pipe symbol in value_template.
looks like when i upgraded to 8.2 there is more breaking stuff… i thought i was cleaning up error logs now others produced lol more topics to ask i see lol
@123
guess i did something wrong… i tried the new code… but its also not liking the avaliablity template… when i do check configuration
what did i do wrong
it was working but now its not… this is the error
Configuration invalid!
Invalid config for [sensor.template]: [availability_template] is an invalid option for [sensor.template]. Check: sensor.template->availability_template. (See ?, line ?).
###########################################################
### Used to Show How Many Devices Are On In Each Group ###
###########################################################
- platform: template
availability_template: "{{ state_attr('group.house_lights', 'entity_id') is not none }}"
sensors:
house_lights_on:
friendly_name: "House Lights On"
value_template: >-
{% if states('group.house_lights') == 'on' %}
{%- for item in states.group.house_lights.attributes.entity_id if states(item) == "on" %}
{% if loop.last %}
{{loop.index}}
{% endif %}
{% endfor %}
{% else %}
0
{% endif %}
outdoor_lights_on:
friendly_name: "Outdoor Lights On"
availability_template: "{{ state_attr('group.outdoor_lights', 'entity_id') is not none }}"
value_template: >-
{% if states('group.outdoor_lights') == 'on' %}
{%- for item in states.group.outdoor_lights.attributes.entity_id if states(item) == "on" %}
{% if loop.last %}
{{loop.index}}
{% endif %}
{% endfor %}
{% else %}
0
{% endif %}
building_lights_on:
friendly_name: "Building Lights On"
availability_template: "{{ state_attr('group.building_lights', 'entity_id') is not none }}"
value_template: >-
{% if states('group.building_lights') == 'on' %}
{%- for item in states.group.building_lights.attributes.entity_id if states(item) == "on" %}
{% if loop.last %}
{{loop.index}}
{% endif %}
{% endfor %}
{% else %}
0
{% endif %}
hot_water_tanks_on:
friendly_name: "Hot Water Tanks On"
availability_template: "{{ state_attr('group.hotwater_tanks', 'entity_id') is not none }}"
value_template: >-
{% if states('group.hotwater_tanks') == 'on' %}
{%- for item in states.group.hotwater_tanks.attributes.entity_id if states(item) == "on" %}
{% if loop.last %}
{{loop.index}}
{% endif %}
{% endfor %}
{% else %}
0
{% endif %}
grow_lights_on:
friendly_name: "Grow Lights On"
availability_template: "{{ state_attr('group.grow_lights', 'entity_id') is not none }}"
value_template: >-
{% if states('group.grow_lights') == 'on' %}
{%- for item in states.group.grow_lights.attributes.entity_id if states(item) == "on" %}
{% if loop.last %}
{{loop.index}}
{% endif %}
{% endfor %}
{% else %}
0
{% endif %}
freezers_on:
friendly_name: "Freezers On"
availability_template: "{{ state_attr('group.freezers', 'entity_id') is not none }}"
value_template: >-
{% if states('group.freezers') == 'on' %}
{%- for item in states.group.freezers.attributes.entity_id if states(item) == "on" %}
{% if loop.last %}
{{loop.index}}
{% endif %}
{% endfor %}
{% else %}
0
{% endif %}
pumps_on:
friendly_name: "Pumps On"
unit_of_measurement: "Pumps On"
value_template: >-
{{ expand(state_attr('group.pumps', 'entity_id'))
selectattr('state', 'eq', 'on') | list | count }}
availability_template: "{{ state_attr('group.pumps', 'entity_id') is not none }}"
outdoor_devices_on:
friendly_name: "Outdoor Devices On"
availability_template: "{{ state_attr('group.outdoor_devices', 'entity_id') is not none }}"
value_template: >-
{% if states('group.outdoor_devices') == 'on' %}
{%- for item in states.group.outdoor_devices.attributes.entity_id if states(item) == "on" %}
{% if loop.last %}
{{loop.index}}
{% endif %}
{% endfor %}
{% else %}
0
{% endif %}
building_sound_on:
friendly_name: "Building Sound On"
availability_template: "{{ state_attr('group.building_sound', 'entity_id') is not none }}"
value_template: >-
{% if states('group.building_sound') == 'on' %}
{%- for item in states.group.building_sound.attributes.entity_id if states(item) == "on" %}
{% if loop.last %}
{{loop.index}}
{% endif %}
{% endfor %}
{% else %}
0
{% endif %}
garden_sprinklers_on:
friendly_name: "Garden Sprinkers On"
availability_template: "{{ state_attr('group.garden_sprinklers', 'entity_id') is not none }}"
value_template: >-
{% if states('group.garden_sprinklers') == 'on' %}
{%- for item in states.group.garden_sprinklers.attributes.entity_id if states(item) == "on" %}
{% if loop.last %}
{{loop.index}}
{% endif %}
{% endfor %}
{% else %}
0
{% endif %}