Morning Weather Notification | With daily high temperature šŸ„ŗ

Hi @rossk, it may be that your met office integration does not have that attribute?
Iā€™m using the ClimaCell - Home Assistant integration and that does have a temp low sub-attribute.

Could you post a screenshot of your weather.met_office_daily entity? You might also check the other met office entities and see if they have a lowtemp (or similar) attribute/sub-attribute.

Just FYI, you actually donā€™t need a for loop or namespaces for your high temperature use case. Jinja has a built-in filter called max you can use here, it takes in a list and returns you the largest value in that list. So your template to get the high temperature can just be this:

{{ state_attr('weather.climacell_hourly', 'forecast')
  | map(attribute="temperature")
  | list | max }}

Hereā€™s the result on mine. I tweaked it slightly so you could see both the list of temperatures and the final max result to show how it worked:

Part of the reason namespaces and loops are so awkward in Jinja is because generally you donā€™t need them. Jinja tries to push you to use its streaming filters for handling arrays like map, select, selectattr, max, etc. because they are more performant and lead to cleaner easier to read templates. If you havenā€™t had a chance to read through their doc I would recommend it. It does a good job and shows all the built-in stuff they make available for you.

2 Likes

Oh nice, thank you @CentralCommand ! Yea, I knew there was the max filter, but did not know how to put the results in to a list that the max filter could iterate through. Iā€™ll give it a try and update.

1 Like

Thanks @Noblewolf for the reply, after much time tweaking I discovered pretty much this, my weather integrations did not have a high and low state, simply an hourly temp reading forecast.

I ended up using two different weather integrations and also made an additional loop to populate the lowest temp over the first 16 hours blocks.

Thanks for the inspiration :+1:t2:

Thereā€™s me thinking I had finished my weather project and now I feel the need to re-write it :joy:

Question though in @Noblewolf example his loop would only loop through the first 16, is your code adaptable easily to achieve the same?

Thanks

1 Like

Oh, huh, I missed that, whoops. Yea easy enough, you can just use the python syntax for getting a subarray. So like this:

{{ (state_attr('weather.climacell_hourly', 'forecast')
  | map(attribute="temperature")
  | list)[0:16]
  | max }}

Admittedly its not quite as pretty anymore since thereā€™s no filter to pipe into for that task but it does the job.

As a rule of thumb when you arenā€™t sure how to do something in Jinja, google how to do it in python. Whatever you find will probably also work in Jinja as long as it doesnā€™t try to mutate the state of an object or require importing a library.

2 Likes

Thanks @rossk for pointing out the limit to the first 16 results. The reason I had that was because if you loop through the entire 24 hours youā€™ll probably get the high temperature for the next day (if the next day is warmer). So the 16 item (or hour) limit is to only get the current dayā€™s high temperature.

Thank you @CentralCommand for the great explanations. Iā€™ve updated my original post with your version of the max temperature filter!

1 Like

Just wanted to give a quick update. 2.5 months on and my spouse is still loving the notifications as built. She hadnā€™t mentioned it in a while until she looked at her phone before 7am (automation trigger is 07:00) and mentioned it wasnā€™t there yet.

I considered running the notification whenever she unplugs her phone in a time range 05:00-12:00, but the iOS version of the HA Companion app doesnā€™t update that charging sensor often (like ever 15 minutes) so it isnā€™t a viable trigger. If anyone has an idea of a faster ā€œIā€™m awake because my phone did xā€ trigger Iā€™d love to hear it.

The way I do it is all through HA and motion sensors to know if one of us is awake. After 5am if the bedroom detects motion by the door (indicating someone is leaving the room) then HA waits to see if the other room gets the motion sensor triggered, indicating that someone left the bedroom and entered the next room, then it waits 10 seconds for them to close the door (so a door sensor could also be the source) and sets the house to ā€œOne Awakeā€. Then the next person to repeat the process triggers the house to be ā€œAwakeā€ (helper input), that is how I know itā€™s time to run my morning announcements 3 minutes later (to give you time to wake up before being inundated with stats).

I have quite a bit of automation around this concept of Awake, Napping, Sleeping, One Awake, where the HVAC kicks in, announcements are made, lights come on and other extra notifications like if itā€™s trash day or whatever. We rarely have to do something manually in the morning unless we wakeup before 5am and the triggering doesnā€™t occur then we might have to tell Siri ā€œGood Morningā€ to force the house into Awake mode and start the chain of events.

Neither of us take our phones to the bedroom so that was never an option, plus I donā€™t know if I would like to be reliant on the fact that someone picked up their phone or took it off charge religiously when I have all these sensors around that can pretty accurately determine whatā€™s going on.

2 Likes

Thatā€™s a good method. We both wake up at very different times, sometimes hours apart, so this combo idea is good. Iā€™ll just have to get some more motion sensors.

Yea, itā€™s worked out very well and only takes two sensors to make it work. One of the reasons I did this two person style is because I like to have the temperature set to 60 for bedtime (automatic based on the ā€œSleep Modeā€ and other factors) and she felt like an Eskimo when she woke up first, so the ā€œOne Awakeā€ setting notches the furnace up to 65 for her then 70 when the second person gets up. Thatā€™s a lot to remember when you havenā€™t had coffee yet, so the automation made sense. Itā€™s also nice having that input variable because it also controls when the home automation makes announcements and where, all my automations are keyed to ā€œIf Sleep Mode is Awakeā€.

1 Like

Me and the better half both have iPhones and as you say the HA iOS app sensors donā€™t update frequently enough, so for sensors we his the ic3 integration as these trigger straight away for us.

We also use it to trigger the iPad chargers to maintain the batteries nicely.

Maybe an option to consider if using iCloud.

we just say ā€œalexa whatā€™s the weatherā€ but yeah not very HA oriented.

We use the smart speaker as well, but we only have one in the living room, and she prefers to check the weather before getting dressed and going out of the bedroom. Not more than 20 steps to ask Alexa, but this is about small improvements. :slight_smile:

My whole home automation has been built on a series of small improvements over the past 25+ years of doing home automation (starting with X10). Some big ideas get implemented out of the gate, but mostly as a developer I just put in the basics and build upon it. My One Awake/All Awake system was bull on that, it just started as a way to control the thermostat but has evolved to an entire system.

The automatic morning announcement is a pretty beefy Jinja script with tons of conditions, like if itā€™s going to be over or under a certain temperature and reading the wind forecast to see when the best time to go for a run is to reading out the first scheduled task of the day - all this gets wrapped into what the house tells you about when you wake up.

This is why I love HomeAssistant, itā€™s so flexible to do these kinds of things. I even use different TTS voices for different things, all on the fly via scripting.

1 Like

I assume ā€œone awakeā€ when the (downstairs) hallway motion sensor detects movement for the 1st time after 6am. Anything before that and it assumes still ā€œasleepā€.

How does 'Napping" mode work? Does it lower volumes throughout the house and how do you trigger it?

One awake is when the bedroom motion sensor picks up motion and then the next room detects motion within 2 minutes, then one is awake. The next time the bedroom picks up motion, now itā€™s just fully awake, the rest of the drapes open, heat goes up, so and and so forth. Then, again, motion in the bedroom turns it off, opens the drapes and reverses the process.

Napping is easy, it turns off all the lights in the bedroom, closes the curtains, quits out of certain apps on my PC, turns off all non home automation sounds and done. All my home automation voice prompts bear the condition of ā€œif Sleep Mode == Awakeā€ so that itā€™s never talking when one or more people are sleeping or napping or whatever.

1 Like

I do something similar for nap mode. Nap mode is an input boolian that can be triggered via the UI, Alexa ā€œturn on nap modeā€ or by pressing the ā€˜nap mode onā€™ button in our nursery.
Nap mode puts all Alexas into Do-not-disturb mode, and turns on a night light in the nursery. Then the automation turns this off after an input-number amount of minutes.

Why did you used tomorrow.io weather service? Is it the best choice? I guess Accuweather is the most accurate or?

Tomorrow.io has the hourly forecast that I used to calculate the daily average temperature. I donā€™t think AccuWeather had that at the time.