Difference in syntax?

I have a couple of sensor. The value comes from json request.
Processing is as follows:

    temperatuur:
      friendly_name: 'Temperatuur grandix'
      value_template: >
        {{ state_attr('sensor.grandix', 'temp').outside }}
      unit_of_measurement: '°C'
    windchill:
      friendly_name: 'Gevoelstemperatuur'
      value_template: >
        {{ state_attr('sensor.grandix', 'temp').windchill }}
      unit_of_measurement: '°C'

The error I get is this:

Value cannot be processed as a number: <state sensor.temperatuur=; unit_of_measurement=°C, friendly_name=Temperatuur grandix @ 2020-01-16T07:06:45.028032+01:00> (Offending entity: )

The strange thing is that I have no error message for the windchill sensor. I can see no difference in the syntax. Why is this error occuring?

What does the sensor.grandix show in the
Developers Tools / States.
Also what values are returned if you validate the value templates in
Developer Tools / Templates

1 Like

Can you post a screen shot or copy the attributes of sensor.grandix from the developer tools states menu?

This is screenshot from Developers Tools / States

Schermafdruk van 2020-01-16 10-57-05

This when I put both sensorsd in Developers Tools / Template

Unfortunately i don’t have any sensors with additional attributes, spent an hour trying to make a dummy in node red
can you try

{{ state_attr(‘sensor.grandix’, ‘temp’).outside | float }}

@Harry13

I added this to the sensor.yaml and it works also just like above example.
What I noticed is that there are no new errors in the log file complaining about wrong unit of measurement. So I studied the rest of the log and I saw a line that said that the server Grandix could not been reached two minutes before the error of the unit of measurement. Could it be HA generates an error because it has to work with no or empty value?

Yes but the templating Doc states to use state_attr etc to avoid errors when entities arent ready during startup, so i cant see why it complained.

The doc says following

`state_attr('device_tracker.paulus', 'battery')`  will return the value of the attribute or None if it doesn’t exist.

Could it beso that if json is not available that HA returns “None” and this is processed and generates the error because it is no float.Should I build something like if None then 0 ?

If you want to build safety into it…

{% set attr = state_attr('sensor.grandix', 'temp') %}
{{ attr.windchill if attr != None else 0.0 }}

Thanks Petro. I use this now in my sensor.yaml.
The error occurs imho only when there is no connection with the server so we have to wait :coffee:

This morning when I was still in bed I see someconnection problem again with server Grandix.
There is no error like above anymore in the log, so we can assume that this solution is working. Now I have to examine why the connection drops.
This thread can be closed I think.

1 Like