Closed jhemak closed 3 weeks ago
I don't think there's anything built into the integration at the moment to get the lowest temperature for the next ~24hours so you might need to create a template but I'll ping @alexander0042 in case he has any ideas for this.
Just adding this as a reference: https://github.com/Pirate-Weather/pirateweather/issues/5
@cloneofghosts, thanks for confirming! I am going to use this as a template sensor:
{{ min(state_attr('sensor.pirateweather_daily_forecast', 'forecast')[0].templow | int(100), states('sensor.pirateweather_temperature') | int(100)) }}
I was able to find this resource on the HA forums of someone trying to do something similar. https://community.home-assistant.io/t/how-to-get-max-value-in-sensor-attribute-array/579236
It doesn't take the current temperature into consideration but still may be useful.
Man, you are good. That is the more elegant approach I knew had to exist. Here's how I adapted it .. thoughts?
{{ state_attr('sensor.pirateweather_hourly_forecast','forecast')[:24] | map(attribute='temperature') | list | min }}
Yup, exactly like that. That'll get you the lowest temperature in the next 24 hours and you could probably combine it with the code you posted above to get the lowest temperature in the next 24 hours.
If you're able to get it working I'll add it to the FAQ section in the HA documentation page if you don't mind.
Not sure I need to combine... do I? the last snippet gives the lowest temp in the next 24 hours based on the hourly forecast sensors alone. What would be missing? And of course, feel free to add to the documentation.
You'd only need to combine if you want to take into account the current temperature. If you're fine with the template as it is then we're good and you can mark this as complete.
I did end up adjusting this. I don't know how all these weather sources come together in the API, but Just tonight I saw the current actual temperature several degrees lower than the lowest forecasted temperature of the 24 hourly forecast segments.
Here's the final version:
{{ min(state_attr('sensor.pirateweather_hourly_forecast','forecast')[:24] | map(attribute='temperature') | list | min, states('sensor.pirateweather_temperature') | int(100)) }}
I did end up adjusting this. I don't know how all these weather sources come together in the API, but Just tonight I saw the current actual temperature several degrees lower than the lowest forecasted temperature of the 24 hourly forecast segments.
If you're in the US or parts of Canada the current temperature and the forecasted temperatures come from two different sources which is likely why you're seeing the disconnect between them.
Thanks for reaching out! @cloneofghosts's solution here is perfect, and nicely builds on the existing HA tools! The discrepancy between current and the next 24 hours is a little strange though, so definitely let me know if it happens again
Describe the issue
Hi @cloneofghosts, I am trying to find the simplest way to determine the lowest temperature of the next ~24 hours. I originally tried to use templow for the current day (day 0), however that does not work in cases where the current temperature (e.g. in the morning) is lower than the upcoming overnight low. Do I just need to create a template sensor to calculate the min value between the current temp and templow, or is there a built-in sensor value that would already provide this information? Thank in advance!
Home Assistant version
No response
Integration version
No response
Troubleshooting steps