Help with Automation with booleans to check current state

Hi all!! First time posting here, so thanks in advance for anyone who reads this.

I’m recently started with Home Assistant. I have some experience programming Arduino and electronics, but I’m still discovering this amazing HA world.

I want to have an automation that checks the value of two temperature sensors, and sends me a Telegram message indicating which one is higher. One sensor is an Arduino that I have on my living room, the other is taking the real time temperature outside from OpenWeatherMap. I want the automation to only trigger once (if temperature outside is higher, send a message. Don’t send it again while temperature outside is higher).
Everything works fine except the blocking of the same state. I’m getting a Telegram message every minute, when it checks de value of the sensors.
I’ve been chating with ChatGPT which helped me with the automation, but I cannor get the blocking of the same state to work.

My code for the automation is as follows:

alias: Comparar sensores y enviar notificación a Telegram
trigger:
  - platform: state
    entity_id: sensor.openweathermap_temperature, sensor.termometre_d1mini_temperatura
action:
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: numeric_state
                entity_id: sensor.openweathermap_temperature
                above: sensor.termometre_d1mini_temperatura
              - condition: template
                value_template: "{{ not caso2_activado }}"
        sequence:
          - service: notify.casallestabot
            data:
              message: >-
                La temperatura de OpenWeatherMap es mayor que la temperatura de
                Termometre D1 Mini.
          - service: input_boolean.turn_on
            entity_id: input_boolean.caso1_activado
          - service: input_boolean.turn_off
            entity_id: input_boolean.caso2_activado
      - conditions:
          - condition: and
            conditions:
              - condition: numeric_state
                entity_id: sensor.termometre_d1mini_temperatura
                above: sensor.openweathermap_temperature
              - condition: template
                value_template: "{{ not caso1_activado }}"
        sequence:
          - service: notify.casallestabot
            data:
              message: >-
                La temperatura de Termometre D1 Mini es mayor que la temperatura
                de OpenWeatherMap.
          - service: input_boolean.turn_on
            entity_id: input_boolean.caso2_activado
          - service: input_boolean.turn_off
            entity_id: input_boolean.caso1_activado
variables:
  caso1_activado: "{{ is_state('input_boolean.caso1_activado', 'on') }}"
  caso2_activado: "{{ is_state('input_boolean.caso2_activado', 'on') }}"

Any idea how to make it work??
Hope everything makes sense, English is not my language.

Thanks ALL!!!

You’re using a state trigger without specifying a state for either of the sensors involved, so this will fire every time there is a change in either of them.

There’s no particular benefit in putting everything in one automation, so to start with why not have two? One something like:

platform: numeric_state
entity_id: sensor.outdoor_temperature
for:
  hours: 0
  minutes: 10
  seconds: 0
above: sensor.living_room_motion_sensor_temperature

… and the other with the sensors the other way round. Then they will only fire when one temperature overtakes the other. The for… bit will prevent repeated messages when the two temperatures are almost the same.

If you are using ChatGPT, bear in mind that its training data is all pre-September 2021, so a lot of things will be out of date.

I wish my Spanish was as good as your English. :grinning_face_with_smiling_eyes:

Thanks for your reply.
But on that case it will just fire every 10 minutes, am I right? Where do i put a condition so it only fires once, until the conditions are the other way around?

No - it will only fire when the outside temperature has been higher than the indoor temperature for ten minutes. It won’t fire again until the outside temperature has dropped below the indoor temperature, then risen above it again for ten minutes.

State or numeric state triggers with a value only fire once when the trigger value is crossed in the correct direction. The ten minutes is there to prevent lots of notifications when both sensors are about the same.

Amazing, thanks for your explanation. Will try that and let you know the outcome!