Temperature/Humitidy sensor notification with trigger value

Hello!

I’ve decided to move from Domoticz to Home Assistant. I’ve been configured in the past days my ESP Easy Mega with MQTT, which works perfectly now.

At first, I am trying to configure automation, to trigger my temp sensor, if the value is for testing, over 25.

This is working fine, I get my telegram message, Yeah! Multiple condition and trigger, one automation. My main problem is that I can’t define which sensor it is, so I tried adding custom trigger value and sensor value inside the message, but when I do this. The alert stop sending.

I did one with only one sensor:

- id: '1660521851031'
  alias: High_Temp_Bureau
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.bureau_temperature
    above: '25'
  condition:
  - condition: numeric_state
    entity_id: sensor.bureau_temperature
    above: '25'
  action:
  - service: telegram_bot.send_message
    data:
      message: '{{ trigger.to_state.name }} too high

When I run actions, I get the name, fine, but never when I trigger by heating the sensor. I want also to have the current value, the sensor see, andwish it can be triggered every 30-60mins until it is solve.

Any help is appreciate :slight_smile:

Thanks

Repeating notifications are best handled using the Alert integration

You will need to set up a Telegram notifier if haven’t already done so.

1 Like

Are you sure this is the correct way round? Reason being if you run the automation manually the trigger and conditions are ignored and there for your template message would not be able to render the trigger name, but if automatically triggered by the temp sensor then it would ?

Also I know the above is for testing so this comment may not be so relevant, but there is no need for the condition as you only have one trigger therefore the following condition referencing the same as the trigger is always going to be true.

I assume when heating the sensor for testing the trigger that you made sure it was reading below 25 before hand? As it will only ever trigger once on transitioning from below to above 25.

As @Didgeridrew said, the alert function may be better if you want regular repeated alerts until a set state is reached.

1 Like

That’s what I thought, that automation wouldn’t do, but still trying to figure out what I can do! I already have telegram configured, so I guess I’ll go that way.

@rossk well, I did run the action to make sure it was sending the message, then I took my office temp sensor which was at 24.2C, then I was only blowing on it, enought to bring it to 25C.

But as soon as I used something like: {{ trigger.friendly_name }} in the message, it wouldn’t work, I had to remove.

but I guess automation is more for doing something related to let’s say: a motion sensor, then open light or something.

I’ll digg more about the alert. This is my last thing from the start, to make the full switch to HA!

Thanks guys!

The correct template would be:
{{ trigger.to_state.attributes.friendly_name}}

There are a variety of ways to repeat action sequences in automations, but the Alert integration gives you more control options that would be tedious to set up in an autoamtion.

1 Like

Thanks

Sorry to be like a noob, trying to figure out how, but when I search, I get old post, and some newer post saying you should use this and this.

alert:
    name: High Temperature
    entity_id: sensor.bureau_temperature
    state: "{{ 'states('sensor.bureau_temperature')' >= '25.60')"
    repeat: 30
    message: "La température du sensor Bureau est plus élevé que 25C. Valeur actuelle: {{ state.sensor.bureau_temperature }}"
    notifiers:
      - B2-Telegram

Something liek that? BTW for info, it syas: temperature is high than 25C. The Actual Value is: xx.xx

so I did in the config yaml: alert: !include alerts.yaml and:

notify:
  - platform: "telegram"
    name: B2-Telegram
    chat_id: xxxxxxxxx
    services:
     - service: telegram_bot.send_message

then in the alerts.yaml , the config.

notify:
  - platform: telegram
    name: "B2-Telegram"
    chat_id: xxxxxxxxx
    services:
      - service: telegram_bot.send_message

When you configure your Notifier as above it creates a service notify.b2_telegram… this format is called a slug. You need to use the slugified version for the notifier: value of the Alert.

There were some significant issues in your templates. Make sure you take a look at the Home Assistant templating and Jinja templating documentation

alert:
  name: High Temperature
  entity_id: sensor.bureau_temperature
  state: "{{ states('sensor.bureau_temperature') | float(0) >= 25.6 }}"
  repeat: 30
  message: >
    La température du sensor Bureau est plus élevé que 25C. Valeur actuelle: {{ states('sensor.bureau_temperature') }}
  notifiers:
    - b2_telegram
1 Like

Thanks for taking time to reply and fixe my mistake !

So okay, I did a test for the notify using the dev options:

service: notify.b2_telegram
data: {  
message: "La température du sensor Bureau est plus élevé que 25C. Valeur actuelle: {{ states('sensor.bureau_temperature') }}"
}

And my telegram group have: La température du sensor Bureau est plus élevé que 25C. Valeur actuelle: 24.30

so I know that the message is good, and telegram is working. Now, getting the alert to be triggered. Do I need something else?

I see in the Dev/State: alert.bureau_temperature value is at idle

alerts.yaml

bureau_temperature:
  name: High Temperature
  entity_id: sensor.bureau_temperature
  state: "{{ states('sensor.bureau_temperature') | float(0) >= 25.0 }}"
  repeat: 1
  skip_first: False
  message: >
    La température du sensor Bureau est plus élevé que 25C. Valeur actuelle: {{ states('sensor.bureau_temperature') }}
  done_message: >
    La température du sensor Bureau est maintenant revenu sous les 25C. Valeur actuelle: {{ states('sensor.bureau_temperature') }}
  notifiers:
    - b2_telegram

My guess, is that state: “{{ states(‘sensor.bureau_temperature’) | float(0) >= 25.0 }}” is not doing what I thought it would do as I get no alert. I doN’t know if I need to configure somethign else or it should fire right away.

Any input on this? Everything I read on the community, people use alert for garage door open, but can’t find anyone using for temperature value. They are all using automation for temperature.

Again, thanks for your time!

Sorry, I forgot that Alert doesn’t accept templates directly… you will need to follow the instruction under the Complex Alert Criteria portion of the docs and create a template binary sensor:

template:
  - binary_sensor:
      - name: "Temp Bureau Plus 25"
        state: "{{ states('sensor.bureau_temperature') | float(0) >= 25.0 }}"
bureau_temperature:
  name: High Temperature
  entity_id: sensor.temp_bureau_plus_25
  state: "on"
  repeat: 1
  skip_first: False
  message: >
    La température du sensor Bureau est plus élevé que 25C. Valeur actuelle: {{ states('sensor.bureau_temperature') }}
  done_message: >
    La température du sensor Bureau est maintenant revenu sous les 25C. Valeur actuelle: {{ states('sensor.bureau_temperature') }}
  notifiers:
    - b2_telegram
1 Like

Ahh makes sense!

So yeah, now it is working.

I modified a little bit:

template:
  - binary_sensor:
      - name: "Temp Bureau Plus 25"
        state: "{{ states('sensor.bureau_temperature') | float(0) >= 25.00 }}"``

So I change from 25.0 to 25.00 cause it wouldn’t trigger. And it works perfectly now. Thanks with your help, now I understand more, and I’ll be ready to set all my sensor, and start moving my zwave sensor.

I’m finally making the move to HA!

edit: just made a new change so I wouldn’t get trigger if it’s it’s just for a few sec

  repeat:
     - 5
     - 30
     - 60

I kinda like!

Last question, is it normal after message: >
La température du sensor Bureau est plus élevé que 25C. Valeur actuelle: {{ states(‘sensor.bureau_temperature’) }}

I can’t add a C after the number?

You just need to add the unit designation outside the curly brackets:

message: >
La température du sensor Bureau est plus élevé que 25C. Valeur actuelle: {{ states(‘sensor.bureau_temperature’) }}C
1 Like