Closed wolfspirituk closed 3 months ago
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.
OK Thanks. I can't see how I can mess it up - but always bear in mind that I could! I have many years experience developing professionally and privately, mainly assembler and C, but HA , Jinja2 and templates are a different way of thinking and I can't' haven't worked out how to dig deeper into it.
On Sun, 16 Jun 2024 at 07:37, David Kendall @.***> wrote:
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 https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/blob/develop/custom_components/octopus_energy/api_client/__init__.py#L698 (which would fail if provided the value you specified). This value is then set directly in the sensor https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/blob/develop/custom_components/octopus_energy/electricity/current_demand.py#L87 .
I'll setup a template sensor as you suggest and see if I can recreate it.
— Reply to this email directly, view it on GitHub https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/issues/916#issuecomment-2171090560, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANXLK2PLGF4YTSEHBQ4QPILZHUXENAVCNFSM6AAAAABJLMUP4GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZRGA4TANJWGA . You are receiving this because you authored the thread.Message ID: @.*** com>
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!)
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_energyelectricity ... _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