Temperature notifications to phone not working

Hi,

I have Home assistant app in android phone. I have Arduino wifi temperature sensors connected to HA via mqtt, working fine.

Want to have notifications when temp goes over or below a certain level. Tried it this way:

Configuration → Automations → Add automation
(Trigger, if the normal temp is 21, does this trigger when it goes to 28c?)

platform: state
entity_id: sensor.eteinentemp
to: '25'
for: '00:00:10'
attribute: unit_of_measurement

(Action section):

device_id: 5f3738n323ec1b4ca41ddc3a3aefdbcf
domain: mobile_app
type: notify
title: Eteisessä liian lämmin.
message: Eteisessä liian lämmin!

What would I need to do to get this working?

Only if it stops on 25° on the way, if it jumps over it, it wont trigger. Also it wont trigger because you are monitoring the unit of measurement attribute which will always be °C, the unit is not the state.

Use this instead:

trigger:
  platform: numeric_state
  entity_id: sensor.eteinentemp
  above: '25'
  for: '00:00:10'

Thank you, it works now :slight_smile: :hugs:

Is there a way to get the notification for example every 15 seconds?

Use an alert instead.

This turned too hard for me. Cant get the alert work. I get my temperatures from Arduinos via mqtt.
configuration.yaml:

sensor:
    - platform: mqtt
      state_topic: "home/upstairs/YlakertaTemp"
      name: "ylakertatemp"
      value_template: "{{ value | replace(' C',' ') }}"
      unit_of_measurement: "°C"

And in autiomations.yaml the notification is like this, and wont allow to convert it to alert. Tried also put “repeat” there, but it isnt repeating anything:

- id: '1636234383087'
  alias: Upstairs too hot
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.ylakertatemp
    for: 00:00:01
    above: '22'
  condition: []
  action:
  - device_id: 5f39f21ec1b4ca33dd6b4c3a3aefdbcf
    domain: mobile_app
    type: notify
    title: Upstair too hot!
    message: Upstair too hot!
    repeat: 00:00:20
  mode: single

If I would try to follow that Alert instruction and make it to temperatures, what would be the “platform” I need to use?

Alerts don’t go in your automation.

Put it in your configuration.yaml file.

I tried like this, in configuration.yaml:

alert:
  ylakertatemp:
    name: Upstairs too hot
    entity_id: sensor.ylakertatemp
    above: 22
    repeat: 00:00:15
    can_acknowledge: true 
    skip_first: false
    notifiers:
      - SM-G973F

But it wont accept “above”. I dont know what to put “state” in this. Is this alert method only for boolean states?

Ah. Yes it is only for booleans. You could create a binary template sensor that is on when your temperature is above 22:

template:
  - binary_sensor:
      - name: "Temp Above 22C"
        state: "{{ states('sensor.ylakertatemp')|float(0) > 22 }}"

And then use that in your alert:

alert:
  ylakertatemp:
    name: Upstairs too hot
    entity_id: binary_sensor.temp_above_22c
    state: "on"
    repeat: 00:00:15
    can_acknowledge: true 
    skip_first: false
    notifiers:
      - SM-G973F

As the alert can be acknowledged (cancelled) it is much better than using your automation with a repeat loop, but if you really want to use an automation with a repeat it could be done like this:

- id: '1636234383087'
  alias: Upstairs too hot
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.ylakertatemp
    for: 00:00:01
    above: '22'
  condition: []
  action:
    - repeat:
        while:
          - condition: numeric_state
            entity_id: sensor.ylakertatemp
            above: 22
        sequence:
          - device_id: 5f39f21ec1b4ca33dd6b4c3a3aefdbcf
            domain: mobile_app
            type: notify
            title: Upstair too hot!
            message: Upstair too hot!
          - delay: 15 # send every 15 seconds
  mode: single

Thank you! I will try that.

Edit: Seems that this doesnt work. I need to change that “repeat” a little bit as it didnt accept that time format. That SM-G973F is device name for my phone with app. Dont know what else I should put there. What else could be wrong here?

template:
  - binary_sensor:
    - name: "Temp Above 22C"
      state: "{{ states('sensor.ylakertatemp')|float(0) > 22 }}"

alert:
  matinhuonetemp:
    name: Upstairs too hot
    entity_id: binary_sensor.temp_above_22c
    state: "on"
    repeat: 1
    can_acknowledge: true 
    skip_first: false
    notifiers:
      - SM-G973F

Can you please post your unedited configuration of these items, don’t translate them to English.

Yes, here is another try with another sensor (easier access to heat :slight_smile: )

template:
  - binary_sensor:
    - name: "Eteinen temp above 26c"
      state: "{{ states('sensor.eteinentemp')|float(0) > 23 }}"

alert:
  eteinentemp:
      name: Eteinen liian kuuma
      entity_id: binary_sensor.eteinen_temp_above_26c
      state: on
      repeat: 2
      can_acknowledge: true
      skip_first: false
      notifiers:
        - SM-G973F

States are strings. on is a boolean. You have to quote it to make it a string.

state: 'on'

Hups. Corrected. Still no alert.

Does it matter which one is used, ’ or " ?

No. You can use either of them.

Any errors in your log related to this?

First thouht there were some problems in log to find my phone. But it seemed to relate to automation notification. Turned automation notifications off and these two came when temperature rise:

Command failed: /opt/vc/bin/vcgencmd measure_clock arm
12:51:10 PM – (ERROR) command_line - message first occurred at 12:38:09 PM and shows up 28 times
Error doing job: Task exception was never retrieved
12:48:56 PM – (ERROR) core.py

What does this mean, that notification must be done first? I get notifications to phone, but how do I know if I have done that properly?

"
The alert integration makes use of any of the notification integrations. To setup the alert integration, first, you must setup a notification integration.
"