#Send me a notification when it's cooler outside

1 messages · Page 1 of 1 (latest)

hearty kestrel
#

Hi! I'm brand new to Home Assistant, and I've written my first custom automation, but I'm not sure if it'll work or if I'm using the best practices.

When: a template changes from false to true for 10 minutes:
{ ( states("sensor.patiosensor_temperature" )) < (( states("sensor.bedroomsensor_temperature" ) ]

Then do: perform action 'Notifications: Send a notification via mobile_app_jakes_iphone' with message "Cooler outside, open the windows!"

It's worded that the transition from false to true is the trigger, but I just want to make sure that it's not going to send a notification every for instant that the logic tests true.

Is this an elegant approach to implement this automation? Any feedback is appreciated!

broken arrow
#

correct, it will only trigger when the template result goes from false to true. you want the template to be this though:

{{ states("sensor.patiosensor_temperature") < states("sensor.bedroomsensor_temperature") }}
lofty loom
#

Crazy - I just created almost the same automation an hour ago and came here to try to get help on why it's not executing. I like your template trigger because it will let me add a little buffer: inside > (outside - 1). I'm going to post my issue separately and not hijack yours

valid stirrup
broken arrow
#

shouldn't be needed as of a few years ago i believe

#

all states are indeed strings, but IIRC behavior within templates was changed a while ago

#

certainly wouldn't hurt to do so though

hearty kestrel
#

I'll see if it works tomorrow, if not I'll cast the states

#

Thanks everyone :)

lofty loom
#

I can confirm there isn't a need to cast

unreal forge
broken arrow
#

@valid stirrup @unreal forge

#

that being said, casting to float or int with a default would be best since not doing so would result in an error if one of the entities is unavailable

unreal forge
#

Now try
{{ states('sensor.andy_office_temperature') < "100" }}

broken arrow
#

I get that, but also...

#

Maybe I'm misunderstanding the change with not always returning strings in templates though. And again, casting to float or int is best anyway so it's a moot point

valid stirrup
#

Try {{ "5" }}. The editor will also show that is a number.

broken arrow
#

True

#

Anyway I'll just say I'm wrong so we can all move on lol

valid stirrup
#

I don’t recall what change that was. But if templates convert strings that represent numbers into float outputs, that still wouldn’t affect calculations within the template. The states function still returns the state, which is always a string. So you’re still doing string comparison inside the template, regardless of what the template does when it outputs the final result.

broken arrow
#

Legitimately asking. I have no problem admitting when I'm wrong but I thought the change affected calculations within templates too edit: i'm a dum

#

Again though, casting to float or int with a default is best practice so I should have suggested that from the beginning and avoided this entire conversation 🤣

valid stirrup
#

There’s nothing wrong with comparing strings. It just does the first character in each string first, then moves to the 2nd character. So "200"<"1" will render as false but things like "20.0"<"43" render “correctly” as true. Hence the “unexpected results” comment from TheFes

broken arrow
#

Oh SHIT that's right

#

I'm totally wrong

#

I even knew that and yet I proceeded to argue 🤦‍♂️ 🤣 my bad

valid stirrup
#

Lol we all have to (re)learn at some point

broken arrow
#

Jesus, I feel like an idiot lol

valid stirrup
#

The others in the thread hopefully learned something so it was a good convo anyways. Lol

broken arrow
#

True

unreal forge
# broken arrow I get that, but also...

The template parser converts the result of a template to a native type. So when the result looks like a number, the template parser will convert it to a float or int, even when it's a string.

If you have an input_text.test, you'll see that the following 2 code snippets have different results

action: input_text.set_value
target:
  entity_id: input_text.test
data: 
  value: "{{ '1.0000' }}"
action: input_text.set_value
target:
  entity_id: input_text.test
data: "{{ dict(value='1.00000') }}"
lofty loom
bitter musk
#

I did this a few weeks ago when I got a house fan installed. One additional item I did was add an actionable notification that allows me to turn off my air conditioning. I get the notification to open windows and turn the house fan on, and then I can click another button on the notification that turns the AC state to off. Very easy and efficient.

fleet inlet
#

A tip for the OP: wrap the notification in a script. Then you can extend your notification mechanisms without redoing every automation that generates a notification, which will be dozens of automations one day.

errant glade
#

In my case I have a template helper that sets a boolean if the house is warmer than outside and my automation is triggered by a state change lasting more than 30 minutes. Part of the automation is a check of the internal house temperature, because I only want to know if the house is particularly hot. The automation only runs during the day. The state is also displayed on a dashboard.

lofty loom
fleet inlet
# lofty loom I would love to know more about this.

Sure thing.
So my setup: I have a phone, the Mrs has a phone, I have a home made HUB75 64x32 LED display capable of scrolling messages, and I have my collection of Squeezeboxes. Each of these is capable of receiving a notification. To add to the fun, I use pushover on my phone whereas the Mrs just uses regular HA notifications.
The script has fields for: the message itself, whether to send to phones, whether to send to the HUB75, whether to send to the squeezeboxes and whether this is a “critical” message. The fields for configuring which devices get the notifications is probably redundant but it seemed useful at the time. These all default to on. Some messages only go to the phones for instance.
For the action list each field is tested and the relevant actions performed. For the HUB75 a MQTT message is sent, etc. Currently only pushover makes use of the critical flag, but it could be used elsewhere eg to scroll the message multiple times on the HUB75 screen.
Also I’ve just realised I should add another type of notification for my Voice PE speaker and have it TTS the message, doh.
For anyone interested in the actual code, I’ll link it.
The beauty of this is of course that I can change my means of notification in a central place. So when I add that VoicePE support to my centralised script I shouldn’t have to change any of the dozen or so automations that can generate notifications. Or if I get fedup with pushover, etc.
https://gist.github.com/aslak3/d26787d1edfdb82723ddcdd02d44bcc3

Gist

Generate Announcement. GitHub Gist: instantly share code, notes, and snippets.

#

(Not that I have any problems with Pushover; it’s terrific.)

fleet inlet
#

Fiddling with this script to add my Voice PE has taught me something: the Default value on a field does not assert that value if the caller leaves it off. So this means my tests for a send_to_xyz being set needs to be:
{{ send_to_xyz != false }}
This seems to catch the field being missing, which is not the same as false!
Otherwise I’d have to go round all my automations and add the missing field to the callers, which would suck to put it mildly. I will experiment some more and then update my gist.

unreal forge
#

Correct, the default value is not automatically used.
You can use something like {{ send_to_xyz | default(false) }} to apply a default value in case it is not defined.

fleet inlet
#

Oh nice. That’s cleaner. Cheers!

lofty loom
#

I also want to use an old school style LED matrix display. My 3 minutes of Amazon browsing seemed to only come up with WiFi ones that have apps and whatnot. I'd like a serial device or something with native Z-wave or Zigbee.
Did you design and build your DYI solution from scratch or work off an existing design?

lofty loom
#

Question: As I understand this, if the field send_to_phones is true the first then branch will be evaluated which sets the data.message parameter. Then in this same branch it check for critical and sets data.message again. But this critical check has an else that will also set data.message. It seems the first data.message is superfluous as it will be overwritten by the following code.
Am I misunderstanding YAML, which is very possible?

      - condition: template
        value_template: "{{ send_to_phones }}"
    then:
      - data:
          message: "{{ message }}"
        enabled: true
        action: notify.mobile_app_lizzie_s_phone
      - if:
          - condition: template
            value_template: "{{ critical }}"
        then:
          - data:
              message: "CRITICAL: {{ message }}"
              data:
                sound: tugboat
                priority: 2
                expire: 300
                retry: 60
            action: notify.pushover
        else:
          - data:
              message: "{{ message }}"
            action: notify.pushover```
fleet inlet
#

I have an awful video on YouTube that shows off the notification feature. Let me know if you’re interested and I’ll link it. I’m quite pleased with it, especially the notification handling. You can read the message from a good 20 feet away, and my eyesight is pretty poor. The buzzer in the board helps draw attention to it as well, though I realised I should extend it by honouring a critical flag in the MQTT post by flashing the screen more aggressively and beeping a bit more or something. If you’re interested in electronics at all I have a somewhat lengthy write up on my blog as well.

fleet inlet
lofty loom