Restart an automation after a previously unrealized condition finally comes true

hi,

I launched a smartphone charging warning automation but with the condition: not at night

how to restart this automation when the condition is met (day)???

Thanks

Add a trigger for day?

or add a choice and move the condition(s) there

add a trigger for day ?? i think it s not the solution

in my automation:

trigger:
battery < 15 %
condition: state
entity_id: binary_sensor.journee
state: “on”
action:
notify

if battery < 15 % and the condition is off → no action

after night, i would like to restart automation …

If you want to restart the automation, you need to trigger it, no other way to start an automation.
Can you show your automation comprehensive ? Please use proper formatting

alias: Recharge batterie smartphone Se20 FE  (jacques)
description: ""
trigger:
  - platform: template
    value_template: >-
      {{ (states.sensor.sm_g780g_battery_level.state | int) <
      (states.input_number.battery_minimum.state | int)  }}
condition:
  - condition: state
    entity_id: binary_sensor.journee
    state: "on"
  - condition: state
    entity_id: input_boolean.house_vacation_mode
    state: "off"
  - condition: state
    entity_id: person.carlier
    state: home
    enabled: false
action:
  - variables:
      stop_time: "{{ now() + timedelta(minutes=10) }}"
    enabled: false
  - service: counter.reset
    data: {}
    target:
      entity_id: counter.my_custom_counter
  - repeat:
      until:
        - condition: or
          conditions:
            - condition: state
              entity_id: sensor.sm_g780g_battery_state
              state: charging
            - condition: numeric_state
              entity_id: counter.my_custom_counter
              above: 2
      sequence:
        - service: notify.mobile_app_sm_g780g
          data:
            message: TTS
            data:
              tts_text: >-
                Jacques Il est temps de recharger la batterie de ton smartphone 
                le niveau actuel est  a
                {{states('sensor.sm_g780g_battery_level')}}  pourcent.
              media_stream: alarm_stream_max
              visibility: public
        - service: notify.alexa_media
          data:
            message: >-
              Jacques Il est temps de recharger la batterie de ton smartphone 
              le niveau       actuel est  a
              {{states('sensor.sm_g780g_battery_level')}}  pourcent.
            title: recharge batterie
            target: media_player.echo_dot_carlier
            data:
              type: tts
          enabled: true
        - service: tts.google_translate_say
          data:
            entity_id: media_player.google_media_player
            language: fr
            message: >-
              Jacques il est temps de recharger la batterie de ton smartphone 
              le niveau actuel       est  a 
              {{states('sensor.sm_g780g_battery_level')}}  pourcent.
        - service: counter.increment
          data: {}
          target:
            entity_id: counter.my_custom_counter
        - delay:
            hours: 0
            minutes: 5
            seconds: 0
            milliseconds: 0
mode: restart

if trigger appears at nignt → no action
i want to restart after night

Then don’t make it trigger at night…

{ (states.sensor.sm_g780g_battery_level.state | int) < (states.input_number.battery_minimum.state  | int) and ( now() > today_at("07:00") and now() < today_at("23:00") )  }}

This will only trigger between 07:00 and 23:00

1 Like

If the battery percentage < x% (trigger) arrives at night, the automation will not be activated due to the condition.
but I want the automation to restart when the condition is activated, i.e. the next day

and it becomes 07:00 it will trigger
Or maybe:

{ (states.sensor.sm_g780g_battery_level.state | int) < (states.input_number.battery_minimum.state  | int) and ( states.binary_sensor.journee.state == "on" )  }}

(if binary_sensor.journee.state represents your day time state)

this will trigger when
states.sensor.sm_g780g_battery_level.state < x
and
states.binary_sensor.journee.state becomes “on”
(in which case you should drop the binary_sensor.journee condition :thinking: )

I thought this:

2 triggers
1. {{ (states.sensor.sm_g780g_battery_level.state | int) <
(states.input_number.battery_minimum.state | int) }}
2. entity_id: binary_sensor.day
state: “on”

do the 2 triggers have to be carried out or one of the 2??

THANKS

if either trigger becomes active it will trigger

Shouldn’t both be active? (condition:and)

trigger on both (which makes it trigger when either one happens.) - this is how you catch the event when night time’s over.
condition on both (which makes it execute only if both are true)

alias: Recharge batterie smartphone Se20 FE  (jacques)
description: ""
trigger:
  - platform: template
    value_template: >-
      {{ (states.sensor.sm_g780g_battery_level.state | int) <
      (states.input_number.battery_minimum.state | int)  }}
  - platform: state
    entity_id:
      - binary_sensor.nighttime
    to: "off"
condition:
  - condition: state
    entity_id: binary_sensor.nighttime
    state: "off"
  - condition: template
    value_template: >-
      {{ (states.sensor.sm_g780g_battery_level.state | int) <
      (states.input_number.battery_minimum.state | int)  }}

....

since it needs to be used twice, i’d create a binary_sensor of your template… call it binary_sensor.needs_charge or something like that.

ok…

thanks but one more question

Are triggers in automation always of the AND type???

no, that’s why i said '(which makes it trigger when either one happens.) ’
triggers are by default ‘or’
conditions are by default ‘and’

ok many thanks

I thought that the triggers were always AND, so it is enough for one trigger to be effective for the automation to start

very strange when i ask CHATGPT: (gemini)

my question:

" in home assistant , Are triggers in automation always of the AND type"

No, triggers in Home Assistant automations are not always of the AND type. Home Assistant offers two main ways to define triggers for automations:

  1. AND Triggers: These require all defined triggers to be true for the automation to activate.
  2. OR Triggers: These require only one of the defined triggers to be true for the automation to activate.

Here’s a breakdown of how to distinguish between them:

AND Triggers:

`YAMLtrigger:

  • platform: state
    entity_id: door.front_door
    state: open
  • platform: sun
    event: sunset`

This automation will only activate if the front door is open AND the sun has set.

OR Triggers:

`YAMLtrigger:

  • platform: state
    entity_id: sensor.temperature
    state: > 25
    - or:
  • platform: state
    entity_id: door.back_door
    state: open`

This automation will activate if the temperature is greater than 25°C OR the back door is open.

In summary:

  • Home Assistant provides flexibility by offering both AND and OR triggers.
  • The choice depends on the desired behavior of your automation.
  • Use AND triggers when all conditions must be met for activation.
  • Use OR triggers when activation should occur based on any of the defined conditions.

Still I guess this is easier:

alias: Recharge batterie smartphone Se20 FE  (jacques)
description: ""
trigger:
  - platform: template
    value_template: >-
      {{ ((states.sensor.sm_g780g_battery_level.state | int) <       
         (states.input_number.battery_minimum.state | int)) and
         (states.binary_sensor.journee.state == "on" ) and
         (states.input_boolean.house_vacation_mode.state == "off" ) }}
condition:
  - condition: state
    entity_id: person.carlier
    state: home
    enabled: false
action:
  - variables:
      stop_time: "{{ now() + timedelta(minutes=10) }}"
    enabled: false
  - service: counter.reset
    data: {}
    target:
      entity_id: counter.my_custom_counter
  - repeat:
      until:
        - condition: or
          conditions:
            - condition: state
              entity_id: sensor.sm_g780g_battery_state
              state: charging
            - condition: numeric_state
              entity_id: counter.my_custom_counter
              above: 2
      sequence:
        - service: notify.mobile_app_sm_g780g
          data:
            message: TTS
            data:
              tts_text: >-
                Jacques Il est temps de recharger la batterie de ton smartphone 
                le niveau actuel est  a
                {{states('sensor.sm_g780g_battery_level')}}  pourcent.
              media_stream: alarm_stream_max
              visibility: public
        - service: notify.alexa_media
          data:
            message: >-
              Jacques Il est temps de recharger la batterie de ton smartphone 
              le niveau       actuel est  a
              {{states('sensor.sm_g780g_battery_level')}}  pourcent.
            title: recharge batterie
            target: media_player.echo_dot_carlier
            data:
              type: tts
          enabled: true
        - service: tts.google_translate_say
          data:
            entity_id: media_player.google_media_player
            language: fr
            message: >-
              Jacques il est temps de recharger la batterie de ton smartphone 
              le niveau actuel       est  a 
              {{states('sensor.sm_g780g_battery_level')}}  pourcent.
        - service: counter.increment
          data: {}
          target:
            entity_id: counter.my_custom_counter
        - delay:
            hours: 0
            minutes: 5
            seconds: 0
            milliseconds: 0
mode: restart

Note you can even move the vacation and person home condition to the template.
I left the person condition out, as I noted it is disabled :thinking:

yes very interesting thanks

That’s because ChatGPT’s answers are nonsense. Triggers are instantaneous events like “the door opens” not states like “the door is open”.

To get the behaviour you might be thinking of as “AND” triggers, you trigger off each thing, and check for both things in the condition:

Trigger (event):

  • on battery dropping below 15%
  • on it becoming daytime

Condition (state):

  • battery is below 15%
  • it is daytime

That will only get to the action if both things (low battery level and daytime) are true, and that will happen at the moment the second thing becomes true.

chatgpt’ :+1: :+1: :+1: :+1:nonsense: