After some researches, I found the template sensors…
template:
- sensor:
- name: "Time heater on"
unique_id: time_heating
device_class: 'duration'
unit_of_measurement: min
state_class: total_increasing
state: >
{% if is_state('sensor.heater', 'heat') %}
{{ (as_timestamp(now()) - as_timestamp('2023-05-01T06:54:44.000Z'))/60}}
{% else %}
{{ this.state }}
{% endif %}
I dont’ know yet why, but yesterday, it seemed to work. Now, it gives me absurd results.
The dev mod gives me the result of
{{ (as_timestamp(now()) - as_timestamp(‘2023-05-01T06:54:44.000Z’))/60}}
when the heater’s state is ‘heat’
The logs give me this error
Error adding entities for domain sensor with platform template
Error while setting up template platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 583, in state
numerical_value = float(value) # type:ignore[arg-type]
^^^^^^^^^^^^
ValueError: could not convert string to float: 'unavailable'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 471, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 749, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 849, in add_to_platform_finish
await self.async_added_to_hass()
File "/usr/src/homeassistant/homeassistant/components/template/sensor.py", line 224, in async_added_to_hass
await super().async_added_to_hass()
File "/usr/src/homeassistant/homeassistant/helpers/template_entity.py", line 409, in async_added_to_hass
await self._async_template_startup()
File "/usr/src/homeassistant/homeassistant/helpers/template_entity.py", line 380, in _async_template_startup
result_info.async_refresh()
File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 974, in async_refresh
self._refresh(None)
File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1154, in _refresh
self.hass.async_run_hass_job(self._job, event, updates)
File "/usr/src/homeassistant/homeassistant/core.py", line 618, in async_run_hass_job
hassjob.target(*args)
File "/usr/src/homeassistant/homeassistant/helpers/template_entity.py", line 349, in _handle_results
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 590, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 654, in _async_write_ha_state
state = self._stringify_state(available)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 596, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 585, in state
raise ValueError(
ValueError: Sensor sensor.time_heating has device class 'duration', state class 'total_increasing' unit 'min' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'unavailable' (<class 'str'>)
well, I’m quite stucked into nowhere
if someone has any clue, I’d be glad to give it a try
thanks