Trafikverket weather station integration, getting “Entity is currently unavailable”

Hi,

first of all thank you all for a nice upgrades!

I am controlling the house floor heating as function of the outside temperature. I use Trafikverket weather stations as outside temperature input. I live between Fiskebäck and Åbro weather stations. So I use these weather stations to create a sensor that contains the mean value of the two weather stations air temparature, “(TF+TÅ)/2”.

I am running HA on a Raspberry Pi3B+ and I recently upgraded (from 2021.11.2 and OS6.6) to the following system setup:

I can read each weather station air temperature separately, see the temp diagram below:
mean outside temp

But I see that the “Mean Outside Temp” value is not valid anymore. It is at 0*C.
When reviewing the integration entities I recognize that some of the weather stations attributes are disabled by the integration, but not the “sensor.fiskeback_air_temperature” and “sensor.abro_air_temperature” that I use for the mean value.


So the separate air temperature values are presented, but not the “sensor.mean_outside_temp”.
I have the following in my configuration.yaml file:

##################################################################
# Adding sensors below this line! :)
##################################################################
sensor:
    ##################################################################
    # Adding Sun related attribute sensors
    ##################################################################
  - platform: template
    sensors:
      solar_angle:
        friendly_name: "Sun angle"
        unit_of_measurement: 'degrees'
        value_template: "{{ state_attr('sun.sun', 'elevation') }}"

      sunrise:
        value_template: "{{ state_attr('sun.sun', 'next_rising') }}"
    ##################################################################
    #    trafikverket_weatherstation
    ##################################################################
  - platform: trafikverket_weatherstation
    name: Trafikverket Fiskebäck
    api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    station: Fiskebäck
    monitored_conditions:
        - air_temp
        - road_temp
        - humidity
        - precipitation
        - wind_direction
        - wind_direction_text
        - wind_speed
        - wind_speed_max
        - precipitation_amount
        - precipitation_amountname
    ##################################################################
    #    trafikverket_weatherstation
    ##################################################################
  - platform: trafikverket_weatherstation
    name: Trafikverket Åbro
    api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    station: Åbro
    monitored_conditions:
        - air_temp
        - road_temp
        - humidity
        - precipitation
        - wind_direction
        - wind_direction_text
        - wind_speed
        - wind_speed_max
        - precipitation_amount
        - precipitation_amountname

  - platform: template
    sensors:
   ##################################################################
   #     Medelvärdesbilda yttertemperaturer (Åbro och Fiskebäck)
   ##################################################################
      mean_outside_temp:
        friendly_name: 'Mean Outside Temp'
        unit_of_measurement: '°C'
        value_template: "{{(float(states('sensor.trafikverket_fiskeback_air_temperature')) + float(states('sensor.trafikverket_abro_air_temperature')))/2 | round(2)}}"
   ##################################################################
   #     Medelvärdesbilda windspeed (Åbro och Fiskebäck)
   ##################################################################
      mean_outside_windspeed:
        friendly_name: 'Mean Outside Windspeed'
        unit_of_measurement: 'm/s'
        value_template: "{{(float(states('sensor.trafikverket_fiskeback_wind_speed')) + float(states('sensor.trafikverket_abro_wind_speed')))/2 | round(2)}}"
   ##################################################################
   #     Medelvärdesbilda wind direction (Åbro och Fiskebäck)        
   ##################################################################
      mean_outside_w_direction:
        friendly_name: 'Mean Outside w_direction'
        unit_of_measurement: '°'
        value_template: "{{(float(states('sensor.trafikverket_fiskeback_wind_direction')) + float(states('sensor.trafikverket_abro_wind_direction')))/2 | round(2)}}"

I reviewed the logs and found the following error:


TemplateError('TypeError: unsupported operand type(s) for /: 'str' and 'float'') while processing template 'Template("{{(float(states('sensor.trafikverket_fiskeback_air_temperature')) + float(states('sensor.trafikverket_abro_air_temperature')))/2 | round(2)}}")' for attribute '_attr_native_value' in entity 'sensor.mean_outside_temp'

07:12:31 – (ERROR) Template - message first occurred at 07:12:31 and shows up 3 times

Error while processing template: Template("{{(float(states('sensor.trafikverket_fiskeback_air_temperature')) + float(states('sensor.trafikverket_abro_air_temperature')))/2 | round(2)}}")

07:12:31 – (ERROR) helpers/template.py - message first occurred at 07:12:30 and shows up 3 times

I have copied the line:
"{{(float(states('sensor.trafikverket_fiskeback_air_temperature')) + float(states('sensor.trafikverket_abro_air_temperature')))/2 | round(2)}}"

to the Developers tools template and investigated.
I found that the parts:

{{states('sensor.trafikverket_fiskeback_air_temperature')}}
{{states('sensor.trafikverket_abro_air_temperature')}}

booth include “unknown” and that the complete line:

{{(float(states('sensor.trafikverket_fiskeback_air_temperature')) + float(states('sensor.trafikverket_abro_air_temperature')))/2 | round(2)}}

does not even “compute” however it was computing fine in the HA 2021.11.2 and OS6.6 setup.

I have tried to rearrange and altered the line creating the "sensor.mean_outside_temp” but it seems I
can unfortunatly not figure out how to change the line based on the error message and what is the root cause to the issue.

So I tried to minimize the challenge to below line, in order to find the root cause.

   ##################################################################
   #     Medelvärdesbilda yttertemperaturer (Åbro och Fiskebäck)
   ##################################################################
      mean_outside_temp:
        friendly_name: 'Mean Outside Temp'
        unit_of_measurement: '°C'
        value_template: "{{states('sensor.trafikverket_fiskeback_air_temperature')|float}}"

This is not creating any errors but the "sensor.mean_outside_temp” is not presenting the fiskeback_air_temperature.

Because the
{{states('sensor.trafikverket_fiskeback_air_temperature')}}
is still delivering “unknown”.

I am unfortunatly out of ideas, anyone else that has any ideas?

I wanted to make a good topic explaination and it became a little long, sorry for that.

Br Christian

Hi,

I found the root cause to the problem.

After the HA update, the sensor name is not: sensor.trafikverket_fiskeback_air_temperature any more, it is sensor.fiskeback_air_temperature !

The correct code is below.

##################################################################
# Adding sensors below this line! :)
##################################################################
sensor:
    ##################################################################
    # Adding Sun related attribute sensors
    ##################################################################
  - platform: template
    sensors:
      solar_angle:
        friendly_name: "Sun angle"
        unit_of_measurement: 'degrees'
        value_template: "{{ state_attr('sun.sun', 'elevation') }}"

      sunrise:
        value_template: "{{ state_attr('sun.sun', 'next_rising') }}"
    ##################################################################
    #    trafikverket_weatherstation
    ##################################################################
  - platform: trafikverket_weatherstation
    name: Trafikverket Fiskebäck
    api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    station: Fiskebäck
    monitored_conditions:
        - air_temp
        - road_temp
        - humidity
        - precipitation
        - wind_direction
        - wind_direction_text
        - wind_speed
        - wind_speed_max
        - precipitation_amount
        - precipitation_amountname
    ##################################################################
    #    trafikverket_weatherstation
    ##################################################################
  - platform: trafikverket_weatherstation
    name: Trafikverket Åbro
    api_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    station: Åbro
    monitored_conditions:
        - air_temp
        - road_temp
        - humidity
        - precipitation
        - wind_direction
        - wind_direction_text
        - wind_speed
        - wind_speed_max
        - precipitation_amount
        - precipitation_amountname

  - platform: template
    sensors:
   ##################################################################
   #     Medelvärdesbilda yttertemperaturer (Åbro och Fiskebäck)
   ##################################################################
      mean_outside_temp:
        friendly_name: 'Mean Outside Temp'
        unit_of_measurement: '°C'
        value_template: "{{(float(states('sensor.fiskeback_air_temperature')) + float(states('sensor.abro_air_temperature')))/2 | round(2)}}"
   ##################################################################
   #     Medelvärdesbilda windspeed (Åbro och Fiskebäck)
   ##################################################################
      mean_outside_windspeed:
        friendly_name: 'Mean Outside Windspeed'
        unit_of_measurement: 'm/s'
        value_template: "{{(float(states('sensor.fiskeback_wind_speed')) + float(states('sensor.abro_wind_speed')))/2 | round(2)}}"
   ##################################################################
   #     Medelvärdesbilda wind direction (Åbro och Fiskebäck)        
   ##################################################################
      mean_outside_w_direction:
        friendly_name: 'Mean Outside w_direction'
        unit_of_measurement: '°'
        value_template: "{{(float(states('sensor.fiskeback_wind_direction')) + float(states('sensor.abro_wind_direction')))/2 | round(2)}}"

Now it works again.
Happy holidays!

BR Christian

1 Like