When temperature goes below 16°C, notify mobiles and send name of thermostat / room

So I’ve got an automation that triggers when temperature drops below 16°C, it sends a notification to our 2 mobile phones. It works quite well as a reminder to close a window in the winter, but what would be better is if the notification message contained the name of the actual thermostat / room that reported the temperature drop. I’ve searched around the documentation but can’t find the correct place that describes how the syntax for message scripting works. Can I report the friendly name or even just the associated room of that thermostat?

alias: Temperatur Warnung wenn 16°
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - climate.thermostat_1og_arbeitszimmer_localtuya
      - climate.thermostat_1og_bad_localtuya
      - climate.thermostat_1og_kinderzimmer_localtuya
      - climate.thermostat_1og_schlafzimmer_localtuya
      - climate.thermostat_dachgeschoss_localtuya
      - climate.thermostat_eg_flur_wc_localtuya
      - climate.thermostat_eg_kueche_localtuya
      - climate.thermostat_eg_wohnzimmer_localtuya
    attribute: current_temperature
    below: 16.1
condition: []
action:
  - service: notify.mobile_app_samsung_s20
    data:
      message: Check die Thermostate und ob Fenster offen sind!
      title: Temperatur 16°C irgendwo
      data:
        clickAction: /lovelace/temperatur
        color: red
  - service: notify.mobile_app_samsung_sirgendwas
    data:
      message: Check die Thermostate und ob Fenster offen sind!
      title: Temperatur 16°C irgendwo
      data:
        clickAction: /lovelace/temperatur
        color: red
mode: single

This wil give you the thermostat friendly name and fall back to the entity id if no friendly name exists:

 {{ trigger.to_state.name }}

This will give you the area name of the trhermostat:

{{ area_name(trigger.entity_id) }}

So:

action:
  - service: notify.mobile_app_samsung_s20
    data:
      message: "Check die {{ trigger.to_state.name }} Thermostate und ob Fenster offen sind!"
      title: Temperatur 16°C irgendwo
      data:
        clickAction: /lovelace/temperatur
        color: red
1 Like

Hey Tom, that didn’t seem to work. Here’s what the error from the traces of the automation:

the error aside, where could I read up on the syntax of the curly brackets scripting and what’s possible to do with it and how to call the different attributes? a bit lost on that here.

Did you trigger it manually?

If so there are no triggers and thus no trigger state objects.

Try triggering it by changing the value of the attribute in Developer Tools → States.

Ah right you are, setting the state via developer tools did trigger it. The title of the message however was “Temperatur 16° in None”, so apparently it wasn’t able to get the area name from the entity id. Do you know how to fix that?

Does the triggering thermostat have an area set?

Look at the trace for your automation, go to the first step and then click the changed variables tab, you’ll see the trigger data

It does, that’s what confuses me

i mean I’m seeing the data, but not sure what to do about it. at least no mention of area_name anywhere

if you post the data we can help, area_name is just a helper function that we can use on the entity_id which will be in the trigger data

changed variable of the first step, I triggered the automation by setting the current_temperature of a thermostat manually to 14° via Developer tools

this:
  entity_id: automation.temperatur_warnung_wenn_15_5deg
  state: 'on'
  attributes:
    last_triggered: '2023-04-09T10:07:55.953751+00:00'
    mode: single
    current: 0
    id: '1669107328600'
    friendly_name: Temperatur Warnung wenn 16°
  last_changed: '2023-04-09T09:41:05.134422+00:00'
  last_updated: '2023-04-09T10:07:56.672885+00:00'
  context:
    id: 01GXJQS51G9SDJRD0SFG53SVWN
    parent_id: 01GXJQS51008GMVAZXR9VWHVKN
    user_id: null
trigger:
  id: '0'
  idx: '0'
  alias: null
  platform: numeric_state
  entity_id: climate.thermostat_1og_arbeitszimmer_localtuya
  below: 16.1
  above: null
  from_state:
    entity_id: climate.thermostat_1og_arbeitszimmer_localtuya
    state: 'off'
    attributes:
      hvac_modes:
        - heat
        - auto
        - 'off'
      min_temp: 7
      max_temp: 35
      target_temp_step: 0.5
      current_temperature: 20.5
      temperature: 21.5
      raw_state: false
      friendly_name: Thermostat 1OG Arbeitszimmer
      supported_features: 1
    last_changed: '2023-04-09T09:19:50.498887+00:00'
    last_updated: '2023-04-09T11:19:02.068275+00:00'
    context:
      id: 01GXJVVB5MMNXPVP4JCM0ASYV9
      parent_id: null
      user_id: null
  to_state:
    entity_id: climate.thermostat_1og_arbeitszimmer_localtuya
    state: 'off'
    attributes:
      hvac_modes:
        - heat
        - auto
        - 'off'
      min_temp: 7
      max_temp: 35
      target_temp_step: 0.5
      current_temperature: 14
      temperature: 21.5
      raw_state: false
      friendly_name: Thermostat 1OG Arbeitszimmer
      supported_features: 1
    last_changed: '2023-04-09T09:19:50.498887+00:00'
    last_updated: '2023-04-09T14:48:41.489326+00:00'
    context:
      id: 01GXK7V7RHFGSWHPB00BD9S89B
      parent_id: null
      user_id: e80b40c4f87447f2b82379ec67f30c98
  for: null
  description: numeric state of climate.thermostat_1og_arbeitszimmer_localtuya

and the actual automation is currently like this:

alias: Temperatur Warnung wenn 16°
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - climate.thermostat_1og_arbeitszimmer_localtuya
      - climate.thermostat_1og_bad_localtuya
      - climate.thermostat_1og_kinderzimmer_localtuya
      - climate.thermostat_1og_schlafzimmer_localtuya
      - climate.thermostat_dachgeschoss_localtuya
      - climate.thermostat_eg_flur_wc_localtuya
      - climate.thermostat_eg_kueche_localtuya
      - climate.thermostat_eg_wohnzimmer_localtuya
    attribute: current_temperature
    below: 16.1
condition: []
action:
  - service: notify.mobile_app_samsung_s20
    data:
      message: "{{ trigger.to_state.name }} meldet 16°C, check ob Fenster offen sind!"
      title: Temperatur 16°C im {{ area_name('trigger.entity_id') }}
      data:
        clickAction: /lovelace/temperatur
        color: red
mode: single

Change {{ area_name('trigger.entity_id') }} to {{ area_name(trigger.entity_id) }}

I think that’s all you need

2 Likes

Yup, that did the trick, area is getting reported properly.

Any idea what the syntax would need to be to change
message: '{{ trigger.to_state.name }} meldet 16°C, check ob Fenster offen sind!'
and replace 16°C with the actual temperate that the thermostat is reporting? And where I could read up about all these proper syntaxes?

Looks like

{{ trigger.to_state.attributes.current_temperature }}

Could also be this, not sure what that value is in your entity

{{ trigger.to_state.attributes.temperature }}

That will just be the number so the full thing would be like this:

message: '{{ trigger.to_state.name }} meldet {{ trigger.to_state.attributes.current_temperature }}°C, check ob Fenster offen sind!'

Not too sure where to read about this specifically, but both the home assistant docs and the developer docs will cover it

1 Like

yep, that also worked :+1:

Not too sure where to read about this specifically, but both the home assistant docs and the developer docs will cover it

what I mean is I’ve read around on the HA website and simply can’t find the right section where this syntax thing is explained. maybe I’m missing it, could you point me to the right direction?

You might be talking about “jinja2” syntax rather than home assistant specifically. Try looking up jinja2 tutorials and see if that helps you. That’s the basic syntax then hopefully the home assistant docs make more sense

1 Like