Help with automation that checks if a sensor value increases

Hello,
i’d need some help with a couple of automations i can’t get to work as needed :slight_smile:

  1. i have a zigbee valve for watering my garden. I “basically” works, but rarely (i’d say once a month) it does not close (i think it’s a matter of water pressure?) so it goes on watering also after the end of the schedule. In this case, the valve is reported as correctly closed, but the water consumption sensor goes on counting. So i want an automation that finds out when. with the valve closed, the consumption sums up. So, throught the loved old “copy and paste”, i tried with something like this, that obviously does not work (i get a notification every night exactly when the schedule ends). Probably it’s the “last” increase when the valve gets closed that comes AFTER the closing event, but i don’t know how to insert a “delay” in this.
alias: Alert Sprinkler
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.sprinkler_sommatoria_consegnata
    for:
      hours: 0
      minutes: 0
      seconds: 5
condition:
  - condition: and
    conditions:
      - condition: template
        value_template: "{{ trigger.from_state.state|int(0) < trigger.to_state.state|int(0) }}"
      - condition: state
        entity_id: switch.sprinkler_interruttore
        state: "off"
action:
  - action: notify.mobile_app_massicell
    data:
      message: Unexpected watering event
      title: Sprinkler
mode: single
  1. since my wife has some relationship problems with Alexa and is able to turn on EVERITHING when trying to do something totally different (lol) i set up an automation to notify when AC is turned on. This basically works, but i get notifications also when the AC controller goes unavailable and gets back available (e.g. when i restart the wifi ap). How can i exclude this?
alias: Notifica condizionatore
description: ""
trigger:
  - platform: state
    entity_id:
      - climate.study_ac
    attribute: hvac_action
    from: "off"
  - platform: state
    entity_id:
      - climate.living_ac
    attribute: hvac_action
    from: "off"
  - platform: state
    entity_id:
      - climate.bedroom_ac
    attribute: hvac_action
    from: "off"
condition: []
action:
  - data:
      title: AC On
      message: AC has been turned on
    action: notify.mobile_app_massicell
mode: single

Thanks :slight_smile:

Hi @MassiPi

For your second question, do you just need to add to: "on" like this:

alias: Notifica condizionatore
description: ""
trigger:
  - platform: state
    entity_id:
      - climate.study_ac
    attribute: hvac_action
    from: "off"
    to: "on"
  - platform: state
    entity_id:
      - climate.living_ac
    attribute: hvac_action
    from: "off"
    to: "on"
  - platform: state
    entity_id:
      - climate.bedroom_ac
    attribute: hvac_action
    from: "off"
    to: "on"
condition: []
action:
  - data:
      title: AC On
      message: AC has been turned on
    action: notify.mobile_app_massicell
mode: single

You may want to remove the from: "off" keys as this will prevent the automation triggering when the state goes from unavailable to on

For your first question, what happens if you remove this bit:

    for:
      hours: 0
      minutes: 0
      seconds: 5

hello,
thanks, but i’m not sure this is gonna work. Climate entities doesn’t even have a “on” state (at least, explicit), do you think this can be used to cover all possible states? (cooling, heating, fan, etc)? I can’t select something like that from GUI

that was the first version, and it behaves the same…

Okay. So you can list multiple states in the to: like this:

      to:
        - "cleaning"
        - "returning"

You can use developer tools to find the state names to use.

You can also do not_to: "unavailable"

1 Like

Could you try making a new automation without the for: and without the conditions and have this send you a notification that shows you what the before and after trigger states are.

thanks, i’ll give to both ideas a try :slight_smile:

Also, maybe try uning float(0) rather than int(0) as the numbers may be equal when the numbers are rounded to integers.

it seems you can’t use to: and not_to together :slight_smile:
but it seems this works:

alias: Notifica condizionatore
description: ""
trigger:
  - platform: state
    entity_id:
      - climate.study_ac
    attribute: hvac_action
    from: "off"
    to:
      - cooling
      - heating
      - fan
      - drying
      - idle
  - platform: state
    entity_id:
      - climate.living_ac
    attribute: hvac_action
    from: "off"
    to:
      - cooling
      - heating
      - fan
      - drying
      - idle
  - platform: state
    entity_id:
      - climate.bedroom_ac
    attribute: hvac_action
    from: "off"
    to:
      - cooling
      - heating
      - fan
      - drying
      - idle
condition: []
action:
  - data:
      title: AC On
      message: >-
        {{ trigger.to_state.name }} has been turned to {{ trigger.to_state.state
        }}
    action: notify.mobile_app_massicell
mode: single

i have to admin it’s not totally clear the coherence of values: i’m filtering the climate states, and i have to insert basically the action (e.g.: COOLING), but when the notification is sent and it sends the actual state, it sends COOL.

For the second automation, stupid me, it was enough to force in conditions that the valve was off for some seconds…

thanks!

1 Like

Hi MassiPi,

Call me crazy, but This all might fix your problem fine. My experience with a device that has an assumed state (RF plugs that are fire and forget to an assumed state) I simply turn them on or off 3 times. That usually get’s it done. Repeat the on or off action multiple times.