bramstroker / homeassistant-powercalc

Custom component to calculate estimated power consumption of lights and other appliances
MIT License
1.01k stars 261 forks source link

ValueError: could not convert string to float: 'unavailable' #1977

Closed Linafri closed 10 months ago

Linafri commented 10 months ago

System Health details

System Information

version core-2023.11.2
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.11.6
os_name Linux
os_version 5.15.90
arch x86_64
timezone Europe/Berlin
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 5000 Installed Version | 1.32.1 Stage | running Available Repositories | 1376 Downloaded Repositories | 20
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 9.5 -- | -- update_channel | stable supervisor_version | supervisor-2023.12.0 agent_version | 1.4.1 docker_version | 20.10.22 disk_total | 30.8 GB disk_used | 9.8 GB healthy | true supported | true board | ova supervisor_api | ok version_api | ok installed_addons | Studio Code Server (5.14.2), Log Viewer (0.15.0), Advanced SSH & Web Terminal (15.0.8), Home Assistant Google Drive Backup (0.110.4), modbus-proxy (1.0.15), CoE to HTTP server (1.1.4), ESPHome (2023.11.6)
Dashboards dashboards | 5 -- | -- resources | 6 views | 5 mode | storage
Recorder oldest_recorder_run | 1. Januar 2024 um 10:12 -- | -- current_recorder_run | 6. Januar 2024 um 17:03 estimated_db_size | 710.78 MiB database_engine | sqlite database_version | 3.41.2
Solcast PV Forecast can_reach_server | ok -- | -- remaining_requests | Exceeded API Allowance rooftop_site_count | 2 polling_hours | 6 -> 17 and once at midnight

Checklist

Describe the issue

when running the power-metering docker-container, I sometimes get:

Traceback (most recent call last):
  File "/app/measure.py", line 333, in <module>
    main()
  File "/app/measure.py", line 325, in main
    measure.start()
  File "/app/measure.py", line 129, in start
    runner_result = self.runner.run(answers, export_directory)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/runner/light.py", line 165, in run
    power = self.take_power_measurement(variation_start_time)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/runner/light.py", line 506, in take_power_measurement
    value = self.measure_util.take_measurement(start_timestamp, retry_count)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/util/measure_util.py", line 47, in take_measurement
    measurement = self.power_meter.get_power()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/powermeter/hass.py", line 33, in get_power
    return PowerMeasurementResult(float(state.state), last_updated)
                                  ^^^^^^^^^^^^^^^^^^
ValueError: could not convert string to float: 'unavailable'

It would be good, if this would be caught and it would be tried again to read the sensor

Reproduction steps

  1. run the container as documented
  2. select a light
  3. run

Error comes from time to time.

Debug logs

Traceback (most recent call last):
  File "/app/measure.py", line 333, in <module>
    main()
  File "/app/measure.py", line 325, in main
    measure.start()
  File "/app/measure.py", line 129, in start
    runner_result = self.runner.run(answers, export_directory)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/runner/light.py", line 165, in run
    power = self.take_power_measurement(variation_start_time)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/runner/light.py", line 506, in take_power_measurement
    value = self.measure_util.take_measurement(start_timestamp, retry_count)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/util/measure_util.py", line 47, in take_measurement
    measurement = self.power_meter.get_power()
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/powermeter/hass.py", line 33, in get_power
    return PowerMeasurementResult(float(state.state), last_updated)
                                  ^^^^^^^^^^^^^^^^^^
ValueError: could not convert string to float: 'unavailable'

Diagnostics dump or YAML config

# Set the power meter to use (hass, shelly, tuya, kasa, manual, tasmota)
POWER_METER=hass

# Set the light controller to use (hass, hue)
LIGHT_CONTROLLER=hass

# Set the media controller to use (for measuring smart speakers).
MEDIA_CONTROLLER=hass

# Set the log level (CRITICAL, ERROR, WARNING, INFO, DEBUG)
LOG_LEVEL=INFO

# time between changing the light params and taking the measurement
SLEEP_TIME=2

# time between taking multiple samples for the same light setting
SLEEP_TIME_SAMPLE=2

# additional time to wait for each significant change in hue
SLEEP_TIME_HUE=1

# additional time to wait for each significant change in saturation
SLEEP_TIME_SAT=1

# additional time to wait for each significant change in color temperature
SLEEP_TIME_CT=1

# Set to a value higher than 1 to take multiple samples to reduce noise
SAMPLE_COUNT=1

# Power Meter Nudging configuration (Useful if PM doesn't report a new reading if readings are unchanged)
# How many times should nudging the Power Meter be attempted?
MAX_NUDGES=2
# When Nudging, how long to hold the non-desired state for?
PULSE_TIME_NUDGE=2
# How long to wait for the Power Meter to settle on the desired measurement after nudging
SLEEP_NUDGE=2

# Brightness level (range 1-255) to start the measurements with.
# Some lights are turned off at 1 so you might need to increase this. Set this at the lowest level at which the light actually turns on
MIN_BRIGHTNESS=5

# Precision for the HS mode loop. You can increase it up to 4 to improve the precision
# of the profile by taking more measurements
HS_BRI_PRECISION=0.3
HS_HUE_PRECISION=0.2
HS_SAT_PRECISION=0.3

# Shelly
SHELLY_IP=192.168.177.36
SHELLY_TIMEOUT=60

# Tuya
TUYA_DEVICE_ID=aaaaaaaaad89682385bbb
TUYA_DEVICE_IP=x.x.x.x
TUYA_DEVICE_KEY=aaaaaaaae1b8abb
TUYA_DEVICE_VERSION=3.3

# Hue
HUE_BRIDGE_IP=x.x.x.x

# Home assistant
HASS_URL=http://192.168.177.185:8123/api
HASS_TOKEN=x
# Set to true when you want to call update_entity service before requesting a power value.
# This can help when your power sensor does not update frequently enough
HASS_CALL_UPDATE_ENTITY_SERVICE=true

# Tasmota
TASMOTA_DEVICE_IP=x.x.x.x

# Kasa
KASA_DEVICE_IP=x.x.x.x

# Predefine answers to questions
# COLOR_MODE=color_temp
GENERATE_MODEL_JSON=true
GZIP=true
MULTIPLE_LIGHTS=false
# LIGHT_ENTITY_ID=xx
MEASURE_DEVICE=Shelly 3 EM
NUM_LIGHTS=1
#LIGHT_MODEL_ID=Kinderbad
#MODEL_NAME=Kinderbad
DUMMY_LOAD=true
POWERMETER_ENTITY_ID=sensor.shellyem3_485519d9d4be_channel_a_power
# RESUME=true
bramstroker commented 10 months ago

Thanks for reporting. I will have a look into fixing this. A bit strange why your powermeter is getting unavailable, I don't have that with any of my shelly's. Probably bad wifi reception.

bramstroker commented 10 months ago

Fixed with #1985 will be in next version.