BottlecapDave / HomeAssistant-OctopusEnergy

Unofficial Home Assistant integration for interacting with Octopus Energy

Home Page:https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sensor.octopus_energy_electricity_ ... _current_demand is returning "0 1" instead of a valid number

wolfspirituk opened this issue · comments

Describe the bug

I use this sensor in an automation. Most of the time it returns a valid float value.
Every few hours it returns '0 1' that is a value, so it passes has_value(), but won't convert to a number.

I can use a default - but you may want to deal with at a lower level as I can't think '0 1' is meant to mean anything and may indicate something else is happening? Of course if it does mean something ....

Reproduction steps

use {% x = states(sensor.octopus_energy_electricity_ ... _current_demand) %}

The actual code I have is in the log below

Expected behaviour

It would return a value float (when converted) or the "unavailable" state

Tariff Code

tariff: E-1R-AGILE-BB-23-12-06-H

Integration Version

10.1.0

Home Assistant Version

2024.6.2

Fresh Install?

Not specified

Home Assistant Logs

redacted
Error while executing automation automation.matrix_settings: ValueError: Template error: int got invalid input '0 1' when rendering template '{%- if request_on -%} { {%- from 'macros.jinja' import mColourIndex -%} {%- if has_value('sensor.octopus_energy_electricity_XXXXX_current_demand') -%} {%- set x = states('sensor.octopus_energy_electricity_XXXXX_current_demand') | round(-1) | int %} "text": "{{ x }}W", "color": {{ ten_colours_B2R[mColourIndex(x,200,300,400,500,650,800,1100,1800,2500)|int] }}, {%- else -%} "text": "n/a", "color": [ 255, 255, 255 ], {%- endif %} "icon": "48329", {{ defaults }} } {%- endif %}' but no default was specified

Confirmation

  • I confirm that I cannot find my solution within the documentation
  • I confirm that I cannot find my solution within the FAQ

Hello and sorry you're seeing this issue.

I have not personally ever seen this error with the demand that is returned from the API. The API converts the value returned by the API into a float (which would fail if provided the value you specified). This value is then set directly in the sensor.

I'll setup a template sensor as you suggest and see if I can recreate it.

Just an update - I broke my code into smaller pieces and found MY error! HA isn't that helpful with the errors IMHO.
So this isn't a bug. Sorry for the goose chase. (thanks for the integration though!)