Problem with payload

I’m receiving data from a sensor. As an example, when I’m listening I see -

Message 1758 received on solar_assistant/inverter_1/pv_power_1/state at 11:12:
518
QoS: 0 - Retain: false

When I paste the following into the Developer Tools>Template -
{{(states(‘sensor.pv_power_1’))|float(default=0)}}

I get -

Result type: number
0
This template listens for the following state changed events:

Entity: sensor.pv_power_1

I’m expecting to see the value 518, not 0. Any idea where I’m going wrong here?

https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

1 Like

First - when you post code to the forum PLEASE enclose it in a preformatted text block (three backticks) spaces are VERY important in YAML and the forum formatting makes them next to impossible to read.

That said - this isn’t valid:

{{(states(‘sensor.pv_power_1’))|float(default=0)}}

you’ve got ‘curly quotes’ around your sensor descriptor -

{{(states('sensor.pv_power_1'))|float(default=0)}}

IO put it in mine and still throwing 0 (I dont have that sensor and default=0 does that) you can also shorthand this as float(0)

Then remove a few of your extra parenthesis for readability…

{{ states('sensor.pv_power_1') | float(0) }}

This should produce your number if its producing it - 0 if anything is wrong, unknown or unavailable. If you put that in and it’s still giving you issues - to determine if the error is the float filter or your sensor - just strip off the last part and see what the result is telling you…

{{ states('sensor.pv_power_1') }}
1 Like

Apologies for the formatting and thanks for your input. You will have guessed I’m no no expert with HA.

{{ states(‘sensor.pv_power_1’) }} returns a string, unknown
{{ states(‘sensor.pv_power_1’) | float(0) }} returns a number, 0

So it seems to me that the sensor readings are not actually being generated, however, when I go to Settings>Select the MQTT tab>Configure>Start Listening, I see that values for sensor.pv_power_1, together with all the other inverter & battery readings, are being continuously updated.

I’m obviously missing something basic here. Any further suggestions would be appreciated.

1 Like