Loop MQTT msg every 10 mins while sensor = X

I don’t see how to post code keeping the correct indents…wait i think i got it. First hit preformatted text, then blockquotes.

I want to send a MQTT msg every 10 mins when my aquarium temp or sump temp falls out of a range and not send it when its not. The device that’s monitoring the temps is capable of sounding a alarm via mqtt msg.

This is the automation part so far, it sends a text msg to my phone… Actually just tested and its not working :frowning:

  - alias: 'Temp Alarm'
    trigger:
      platform: numeric_state
      entity_id: sensor.tank_temp
      above: 79
      below: 75    
    action:
      - service: notify.Sms_alert
        data:
          message: 'Aquarium Temp is {{states.sensor.tank_temp.state}} and Sump is {{states.sensor.sump_temp.state}}'
          target:
            - +1xxxxxxxxxx    

Is there a better way then something like this “How can repeat this automation? - #2 by PhyberApex”, that process just seems long.
The part i plan to adapt is:

automation:
  - alias: 'Porta casa de banho'
    trigger:
      platform: state
      entity_id: binary_sensor.porta_casa_de_banho
      state: 'on'
      for:
        seconds: 20
    action:
      - service: script.stuff

script:
  stuff:
    sequence:
      - condition: state
        entity_id: binary_sensor.porta_casa_de_banho
        state: 'on'
      - service: shell_command.play_wc
      - service: script.stuff_loop
  stuff_loop:
    sequence:
      - condition: state
        entity_id: binary_sensor.porta_casa_de_banho
        state: 'on'
      - delay:
          seconds: 20
      - service: script.stuff

I would use time every 10 mins as the trigger and the temps as the condition and your script as the action.

1 Like

Would that mean if temp falls out of range, then I may need to wait 10 mins before hearing the first alert?

btw…
is this the correct way to call the action

  - alias: 'Temp Alarm'
    trigger:
      platform: numeric_state
      entity_id: sensor.tank_temp
      above: 79
      below: 75    
    action:

You can add the state change of the “alarm via mqtt msg” as another trigger to get a instant notification.

I somewhat followed that link, no scripts, i put this in automations which i believe should yield a notification…

  - alias: 'Temp Alarm 2 test'
    trigger:
      platform: time
      minutes: '/2'
    condition:
      - condition: numeric_state
        entity_id: sensor.tank_temp
        above: 79
        below: 75  
    action:
      - service: notify.Sms_alert
        data:
          message: 'Aquarium Temp is {{states.sensor.tank_temp.state}} and Sump is {{states.sensor.sump_temp.state}}'
          target:
            - +1xxxxxxxxxx

could the issue be the sensor is read as 73.39 and i’m only putting 75 for instance… it should be

condition:
  - condition: numeric_state
    entity_id: sensor.tank_temp
    above: 79.00
    below: 75.00

You can optionally use a value_template to process the value of the state before testing it. This should change it to an integer.

condition:
  condition: numeric_state
  entity_id: sensor.temperature
  above: 17
  below: 25
  # If your sensor value needs to be adjusted
  value_template: {{ int(state.state) }}

You can test the automation in the state dev page by going to the sensor and changing the temp to see if it triggers.

  - alias: 'Temp Alarm 2 test'
    trigger:
      - platform: time
        minutes: '/2'
      - platform: numeric_state
        entity_id: sensor.tank_temp
        value_template: {{ int(state.state) }}
    # Optional
       # value_template: '{{ int(states.sensor.tank_temp.state) }}'
        above: 79
        below: 75
    condition:
      - condition: numeric_state
        entity_id: sensor.tank_temp
        above: 79
        below: 75  
        value_template: {{ int(state.state) }}
    action:
      - service: notify.Sms_alert
        data:
          message: 'Aquarium Temp is {{states.sensor.tank_temp.state}} and Sump is {{states.sensor.sump_temp.state}}'
          target:
            - +1xxxxxxxxxx

Error “invalid key: “OrderedDict([(‘int(state.state)’, None)])”
in “/home/homeassistant/.homeassistant/automations.yaml”, line 36, column 0”

does it work without that line?

did you try to use this commented line?
# value_template: ‘{{ int(states.sensor.tank_temp.state) }}’

did you try above: 79.00 below: 75.00 ?

value_template: ‘{{ int(states.sensor.tank_temp.state) }}

gives me “Template error: UndefinedError: ‘int’ is undefined”

and this also does not work.

  - alias: 'Temp Alarm 2 test'
    trigger:
      - platform: time
        seconds: '/5'
      - platform: numeric_state
        entity_id: sensor.tank_temp
       # value_template: {{ int(state.state) }}
    # Optional
       # value_template: '{{ int(states.sensor.tank_temp.state) }}'
        above: 79.00
        below: 75.00
    condition:
      - condition: numeric_state
        entity_id: sensor.tank_temp
        above: 79.00
        below: 75.00
        #value_template: {{ int(state.state) }}
    action:

I have decided to edit the code on controller “esp9266” to sound alarm instead as this would be more reliable also.

Thank you for your help.