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

ValueError: could not convert string to float: 'None' #10

Closed
marecabo opened this issue May 8, 2020 · 3 comments
Closed

ValueError: could not convert string to float: 'None' #10

marecabo opened this issue May 8, 2020 · 3 comments
Labels
bug Something isn't working.

Comments

@marecabo
Copy link

marecabo commented May 8, 2020

Version of the custom_component
1.4.2 bb1cdba

Configuration

sensors:
# original sensor
  - platform: mqtt
    name: "Sonoff1 Temperature"
    state_topic: "tele/sonoff1/SENSOR"
    unit_of_measurement: '°C'
    value_template: "{{value_json['SI7021'].Temperature}}"

# average sensor
  - platform: average
    name: 'Sonoff1 Temperature Average'
    duration:
      days: 1
    entities:
      - sensor.sonoff1_temperature

# repeat the above with sonoff5 and sonoff6

Describe the bug

When the original sensor entity to compute the average of, is available but has an unknown state, this error occurs.
This might be related to #2?

To Reproduce

  1. Unplug the temperature sensor. (Here i did that for the sonoff1 sensor which is the living room.)
  2. The state of the original temperature sensor entity changes to unknown (see fig 1).
  3. Create the average sensor as shown above and restart HA
    (So during the first start of the average sensor, the original sensor has no value, but there are still values in the period (1 day) to compute the average of, see fig 2)
  4. The average sensor produces that error and does not compute the average value (see fig 3).
  5. Even after plugging the sensor back in so it transmits data to HA and the original sensor entity has a float value again (see living room temp in fig 2 at the right side), the average sensor still throws that error.

The other average sensors (sonoff5 and sonoff6) worked fine, as they had a not-unknown state for their original sensors for > 1 day.

Expected behavior

I expected the average sensor to produce an average value of the configured period of all the not-unknown values in that period. It looks like, the average sensor cannot cope with past (or still ongoing) sections in the state history that have unknown values.

Screenshots

fig 1
image

fig 2
image

fig 3
image

Debug log

Update for sensor.sonoff1_temperature_average fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 279, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 472, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/util/__init__.py", line 240, in wrapper
    result = method(*args, **kwargs)
  File "/config/custom_components/average/sensor.py", line 284, in update
    self._update_state()
  File "/config/custom_components/average/sensor.py", line 472, in _update_state
    current_state = self._get_entity_state(item)
  File "/config/custom_components/average/sensor.py", line 260, in _get_entity_state
    state = self._get_temperature(entity) if self._temperature_mode \
  File "/config/custom_components/average/sensor.py", line 248, in _get_temperature
    temperature = float(temperature)
ValueError: could not convert string to float: 'None'

Thanks for your work at this component! Feel free to let me know how to further assist you in tracing this down.

@marecabo marecabo added the bug Something isn't working. label May 8, 2020
@marecabo
Copy link
Author

These changes fixed it for me: marecabo@29ab960

Is that the right spot for these changes to fix that issue?

@asucrews
Copy link

@marecabo looks like your fix works :) Maybe Pull Requets help this along?

@Limych Limych closed this as completed Sep 6, 2020
Limych added a commit that referenced this issue Mar 27, 2021
@github-actions
Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working.
Projects
None yet
Development

No branches or pull requests

3 participants