Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sensor availability not checked ? #52

Closed
GH2user opened this issue May 5, 2024 · 6 comments
Closed

sensor availability not checked ? #52

GH2user opened this issue May 5, 2024 · 6 comments

Comments

@GH2user
Copy link
Contributor

GH2user commented May 5, 2024

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.

@jeroenterheerdt
Copy link
Owner

what is an availability template?

@GH2user
Copy link
Contributor Author

GH2user commented May 18, 2024

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 }}"

@jeroenterheerdt
Copy link
Owner

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.

@GH2user
Copy link
Contributor Author

GH2user commented Jun 6, 2024

Thanks a lot Jeroen, Will test it later on.

@GH2user
Copy link
Contributor Author

GH2user commented Jun 6, 2024

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?

@Giorsetti
Copy link

Same for me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants