panhans / HomeAssistant

Home Asisstant related stuff like blueprints for automations and scripts.
90 stars 25 forks source link

Sonoff TRV - ValueError: could not convert string to float: #55

Closed Danm72 closed 6 months ago

Danm72 commented 8 months ago
Logger: homeassistant.helpers.event
Source: helpers/event.py:296
First occurred: January 21, 2024 at 4:35:14 PM (183 occurrences)
Last logged: 9:34:23 AM

Error while dispatching event for climate.living_room_trv_sonoff_trvzb_thermostat to <Job track state_changed event {'climate.living_room_trv_sonoff_trvzb_thermostat'} HassJobType.Callback <bound method TrackTemplateResultInfo._refresh of <TrackTemplateResultInfo {Template<template=(sensor: - platform: template sensors: room_temperature_wall_mounted: value_template: "{{ state_attr('climate.living_room_trv_sonoff_trvzb_thermostat', 'current_temperature') | float * 5 }}" unit_of_measurement: °C) renders=440>: <RenderInfo Template<template=(sensor: - platform: template sensors: room_temperature_wall_mounted: value_template: "{{ state_attr('climate.living_room_trv_sonoff_trvzb_thermostat', 'current_temperature') | float * 5 }}" unit_of_measurement: °C) renders=440> all_states=False all_states_lifecycle=False domains=frozenset() domains_lifecycle=frozenset() entities=frozenset({'climate.living_room_trv_sonoff_trvzb_thermostat'}) rate_limit=None has_time=False exception=None is_static=False>}>>>
Error while dispatching event for climate.living_room_trv_sonoff_trvzb_thermostat to <Job track state_changed event {'climate.living_room_trv_sonoff_trvzb_thermostat'} HassJobType.Callback <bound method TrackTemplateResultInfo._refresh of <TrackTemplateResultInfo {Template<template=(sensor: - platform: template sensors: room_temperature_wall_mounted: value_template: "{{ state_attr('climate.living_room_trv_sonoff_trvzb_thermostat', 'current_temperature') | float * 5 }}" unit_of_measurement: °C) renders=442>: <RenderInfo Template<template=(sensor: - platform: template sensors: room_temperature_wall_mounted: value_template: "{{ state_attr('climate.living_room_trv_sonoff_trvzb_thermostat', 'current_temperature') | float * 5 }}" unit_of_measurement: °C) renders=442> all_states=False all_states_lifecycle=False domains=frozenset() domains_lifecycle=frozenset() entities=frozenset({'climate.living_room_trv_sonoff_trvzb_thermostat'}) rate_limit=None has_time=False exception=None is_static=False>}>>>
Error while dispatching event for climate.living_room_trv_sonoff_trvzb_thermostat to <Job track state_changed event {'climate.living_room_trv_sonoff_trvzb_thermostat'} HassJobType.Callback <bound method TrackTemplateResultInfo._refresh of <TrackTemplateResultInfo {Template<template=(sensor: - platform: template sensors: room_temperature_wall_mounted: value_template: "{{ state_attr('climate.living_room_trv_sonoff_trvzb_thermostat', 'current_temperature') | float * 5 }}" unit_of_measurement: °C) renders=444>: <RenderInfo Template<template=(sensor: - platform: template sensors: room_temperature_wall_mounted: value_template: "{{ state_attr('climate.living_room_trv_sonoff_trvzb_thermostat', 'current_temperature') | float * 5 }}" unit_of_measurement: °C) renders=444> all_states=False all_states_lifecycle=False domains=frozenset() domains_lifecycle=frozenset() entities=frozenset({'climate.living_room_trv_sonoff_trvzb_thermostat'}) rate_limit=None has_time=False exception=None is_static=False>}>>>
Error while dispatching event for climate.living_room_trv_sonoff_trvzb_thermostat to <Job track state_changed event {'climate.living_room_trv_sonoff_trvzb_thermostat'} HassJobType.Callback <bound method TrackTemplateResultInfo._refresh of <TrackTemplateResultInfo {Template<template=(sensor: - platform: template sensors: room_temperature_wall_mounted: value_template: "{{ state_attr('climate.living_room_trv_sonoff_trvzb_thermostat', 'current_temperature') | float * 5 }}" unit_of_measurement: °C) renders=446>: <RenderInfo Template<template=(sensor: - platform: template sensors: room_temperature_wall_mounted: value_template: "{{ state_attr('climate.living_room_trv_sonoff_trvzb_thermostat', 'current_temperature') | float * 5 }}" unit_of_measurement: °C) renders=446> all_states=False all_states_lifecycle=False domains=frozenset() domains_lifecycle=frozenset() entities=frozenset({'climate.living_room_trv_sonoff_trvzb_thermostat'}) rate_limit=None has_time=False exception=None is_static=False>}>>>
Error while dispatching event for climate.living_room_trv_sonoff_trvzb_thermostat to <Job track state_changed event {'climate.living_room_trv_sonoff_trvzb_thermostat'} HassJobType.Callback <bound method TrackTemplateResultInfo._refresh of <TrackTemplateResultInfo {Template<template=(sensor: - platform: template sensors: room_temperature_wall_mounted: value_template: "{{ state_attr('climate.living_room_trv_sonoff_trvzb_thermostat', 'current_temperature') | float * 5 }}" unit_of_measurement: °C) renders=448>: <RenderInfo Template<template=(sensor: - platform: template sensors: room_temperature_wall_mounted: value_template: "{{ state_attr('climate.living_room_trv_sonoff_trvzb_thermostat', 'current_temperature') | float * 5 }}" unit_of_measurement: °C) renders=448> all_states=False all_states_lifecycle=False domains=frozenset() domains_lifecycle=frozenset() entities=frozenset({'climate.living_room_trv_sonoff_trvzb_thermostat'}) 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 644, in state
    numerical_value = float(value)  # type:ignore[arg-type]
                      ^^^^^^^^^^^^
ValueError: could not convert string to float: 'sensor:\n  - platform: template\n    sensors:\n      room_temperature_wall_mounted:\n        value_template: "86.5"\n        unit_of_measurement: °C'

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 296, in _async_dispatch_entity_id_event
    hass.async_run_hass_job(job, event)
  File "/usr/src/homeassistant/homeassistant/core.py", line 691, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1215, in _refresh
    self.hass.async_run_hass_job(self._job, event, updates)
  File "/usr/src/homeassistant/homeassistant/core.py", line 691, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 429, in _handle_results
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 945, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1066, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1003, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 951, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 646, in state
    raise ValueError(
ValueError: Sensor sensor.test_template has device class 'temperature', state class 'measurement' unit '°C' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'sensor:
  - platform: template
    sensors:
      room_temperature_wall_mounted:
        value_template: "86.5"
        unit_of_measurement: °C' (<class 'str'>)
panhans commented 8 months ago

Hi, thank you for your feedback.

Could you share the trace log of the automation when the error occurs?

Another question: The unit of your sensor is °C but the value is 86.5. Is there something mixed up in your configuration? It seems the unit must be °F since the value is much too high for °C.

panhans commented 6 months ago

Lack of information.