HADailySensor icon indicating copy to clipboard operation
HADailySensor copied to clipboard

sensor availability not checked ?

Open GH2user opened this issue 9 months ago • 3 comments

I have a max sensor based on the DSMR voltage sensor. This is not available when HADailySensor is starting and thus gives an error.

Logger: custom_components.daily.sensor Source: custom_components/daily/sensor.py:156 integration: Daily Sensor ([documentation](https://github.com/jeroenterheerdt/HADailySensor), [issues](https://github.com/jeroenterheerdt/HADailySensor/issues)) First occurred: 16:00:21 (6 occurrences) Last logged: 16:00:27 unable to convert unavailable to float. Please check the source sensor (sensor.electricity_meter_voltage_phase_l1) is available.

Adding an availability template to each daily_sensor would prevent this.

GH2user avatar May 05 '24 14:05 GH2user

what is an availability template?

jeroenterheerdt avatar May 17 '24 22:05 jeroenterheerdt

It checks for the availability of the sensor, refer https://www.home-assistant.io/integrations/template/ The section on "STATE BASED SENSOR CHANGING THE UNIT OF MEASUREMENT OF ANOTHER SENSOR" is the clearest I suppose. Also a lot of comments on this concept on Tweakers.net (assume you are dutch) and the HA-forum.

code snippet (spacing and code tags are not really working here for some reason; template:

  • sensor:
    • name: "fan speed percentage" unique_id: "IDsensor_fan_speed_percentage" state_class: measurement unit_of_measurement: "%" icon: mdi:fan state: > {{ state_attr('fan.itho_wifi_nrg_21a4','percentage') }} availability: >- {{ states( 'fan.itho_wifi_nrg_ssss' ) not in [ 'unknown', 'unavailable'] }}

or availability: "{{ states('fan.itho_wifi_nrg_ssss') | is_number }}"

GH2user avatar May 18 '24 09:05 GH2user

Right,but that's of course not how it works in python when writing an integration. But I think I get now what you're after.

jeroenterheerdt avatar May 18 '24 14:05 jeroenterheerdt

Thanks a lot Jeroen, Will test it later on.

GH2user avatar Jun 06 '24 18:06 GH2user

Logger: homeassistant Source: custom_components/daily/sensor.py:155 integration: Daily Sensor (documentation, issues) First occurred: 20:07:49 (172 occurrences) Last logged: 20:08:49

Error doing job: Future exception was never retrieved Traceback (most recent call last): File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/daily/sensor.py", line 72, in lambda event: self._handle_update( # pylint: disable=unnecessary-lambda ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/daily/sensor.py", line 102, in _handle_update the_val = self.convert_to_float(input_state) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/daily/sensor.py", line 155, in convert_to_float return float(float_value) ^^^^^^^^^^^^^^^^^^ TypeError: float() argument must be a string or a real number, not 'State'

Mm, not really happy after the restart. You want me to make a new Issue?

GH2user avatar Jun 06 '24 18:06 GH2user

Same for me...

Giorsetti avatar Jun 07 '24 10:06 Giorsetti