Getting yr_sensor icon

Hi!
I try to make template sensor which takes data from yr_sensor.

  - platform: template
    sensors:
      weather_temperature:
        value_template: '{{ states.sensor.yr_temperature.state | round }}'
        friendly_name: 'Outside temperature'
      weather_conditions:
        value_template: '{{ states.sensor.yr_symbol.state }}'
        icon_template: '{{ **????** }}'

I get two problems.

  1. Warning Could not render template Outside temperature, the state is unknown.
  2. I don’t know how to get icon from yr_sensor. State displayed correctly, but what about icon?

Maybe someone know solution…

On the icon, that isn’t supported at the moment. A PR is being done for DarkSky and talk was made by some of the core devs to add this feature to the weather component in the near future as all the individual weather components will be folded into one weather component - much like how the climate component works.

I don’t use this so I am installing it now to see if I can help with the first question, so stand by.

OK, if I put your value template into the template tester in the dev panel (https://WhateverYourURLis/dev-template)

As {{ states.sensor.yr_temperature.state | round }} I get a correct response with the current temp, rounded.

What happens when you do the same? Could it be that it just wasn’t able to connect to YR at the time?

Thanks, I get same results. And frontend renders this sensor correctly. But I still see this error at the beginning of the log file. Seems like my sensor tries get data before yr_sensor loaded.
Using states('sensor.yr_temperature') instead of states.sensor.yr_temperature.state seems to be a better idea, because states('...') firstly checks if entity exists. However expression {{ states('sensor.yr_temperature') }} works in dev-template, but gives error while in config file.
Btw, I noticed, that if unit_of_measurement defined as °C or °F than proper temperature icon is assigned to sensor automatically.

Could you please explain two things for me (or point to proper documentation)?
I learned how to get sensor states by '{{ states.sensor.SensorName.state }}'. As I understood, there is “global” object States and I can get any component state through it, if I know component’s entity_id. Or attribute, for example {{ states.light.LightName.attributes.brightness }}. But I can’t get icon as an attribute, right? And how to figure out all possible attributes? I can see some of them at States tool at hass frontend, but there is no brightness, for example.
Even more mystical is getting attributes in automations. I found statement {{ trigger.to_state.attributes.AtributeName }}. So, when event triggered, an object Trigger is being created and it correspond with entity that triggered event, right? But what .to_state means? What other possible options could be after trigger.?
And are there any other objects, except States and Trigger?
Sorry for so many questions, I honestly read all documentations, but those things are still not 100% clear for me. Thanks a lot.

Take a look at this post for a method of wrapping your template sensor in an if test; that should eliminate the error.

As far as the icon as an attribute, there is a pull request for doing that but it isn’t currently something that is available.

I’m not sure if understood this correctly as I am still learning about templating as well, but the trigger.state happens when a given entity changes states. You have to give it the state you want to match, as in this example:

- alias: "Powered off from Harmony Hub"
  trigger:
    platform: state
    entity_id: remote.living_room
  condition:
    condition: template
    value_template: '{{ trigger.to_state.attributes.current_activity == "PowerOff" }}'
  action:
    service: input_select.select_option
    entity_id: input_select.living_room_tv
    data:
      option: "Powered Off"

This automation changes the value in a input select to a specific value “Powered Off” whenever the value of the attribute current_activity in the entity remote.living_room changes to “PowerOff”.