Hello,
Desperate attempt to understand why my template sensor is not working.
I have this code, the time returns as expected, yet the weather returns unknown
- platform: template
sensors:
#<--------------------- Template for announcements --------------------->
announcement_message_date:
value_template: >-
{% set now = now() %}
Good Morning and welcome to {{ now.strftime('%A') }},
{{ now.strftime('%-d') }} {{now.strftime('%B') }}
announcement_message_weather:
value_template: >-
{% set current_temp = states('sensor.canberra_temp') %}
{% set min_temp = states('sensor.queanbeyan_temp_min_1') %}
{% set max_temp = states('sensor.queanbeyan_temp_max_1') %}
{% set forecast = states('sensor.queanbeyan_extended_text_0') %}
Hello, here is todays weather for Queanbeyan. The current temperature is
{{ current_temp }} degrees. Todays temperture is forecast to be
between {{ min_temp }} and {{ max_temp }} degrees. The outlook for today is
{{ forecast }}. That is all, have a nice day.
entity_id:
- sensor.canberra_temp
- sensor.queanbeyan_temp_min_1
- sensor.queanbeyan_temp_max_1
- sensor.queanbeyan_extended_text_0
If I post the weather code into developer tools template, it returns the expected values, yet the developer tools states returns unknown.
I attempt to update the weather with:
service: homeassistant.update_entity
target:
entity_id: sensor.announcement_message_weather
Yet it still returns unknown. Anyone know why that is?
Connecting to weather forecasts and information has changed recently.
I suggest searching weather forecast this website as you may have to change things.
I know of this post in the cookbook that may help, otherwise maybe someone that has a better handle on this might see your post here.
Definitive guide to Weather integrations 🌦.
Thanks… I just don’t get why it works in developer tools but not as a template sensor.
Something related to the forecast is a LOT of words and info, so it was moved out of attributes into being pulled with a service or something.
If your sensor.queanbeyan_extended_text_0
is giving out what you want as forecast attribute, this is ok. For the template sensor it’s just another sensor.
But what are the entity_id
s at the end for? I forgot a lot about the old format, which you use here (btw. the new template sensors are really good!), but I’m quite sure, there weren’t any entity_id
s.
I thought they were to be added so the entities updated as they changed.
I am not sure why, but I had to make two template sensors. One for the temps and another for the outlook. Combining the two returns unknown… (for an unknown reason!).
So I have:
announcement_message_weather_temp:
value_template: >-
{% set current_temp = states('sensor.canberra_temp') %}
{% set min_temp = states('sensor.queanbeyan_temp_min_1') %}
{% set max_temp = states('sensor.queanbeyan_temp_max_1') %}
"Hello. Here is todays weather for Queanbeyan. The current temperature is {{ current_temp }}
degrees. Todays temperture is forecast to be between {{ min_temp }} and {{ max_temp }}
degrees."
# entity_id:
# - sensor.canberra_temp
# - sensor.queanbeyan_temp_min_1
# - sensor.queanbeyan_temp_max_1
announcement_message_weather_outlook:
value_template: >-
{% set forecast = states('sensor.queanbeyan_extended_text_0') %}
"The outlook for today is {{ forecast }} That is all. Have a nice day."
# entity_id: sensor.queanbeyan_extended_text_0
I commented out the entity_id
lines as well.
I don’t know why, but it works!
That’s strange. But I’d speculate, that something else has solved this, like a restart or such a thing. If you want to, try in a few days to combine the sensors again, and see what happens.
Good you got it working !
1 Like
Couldn’t even combine them into a seperate sensor either.