#How do i add a condition of "was previously on or off for x amount of time" after a change>

1 messages · Page 1 of 1 (latest)

analog walrus
#

When i am walking past my car, it unlocks and stops charging. when i have 1 meter distance, it locks and starts charging again. because i have a telegram confirmation that the car is charging, it becomes annoying quite fast that when i walk by the car i get these notifications on my phone. so i want to make a condition, that it only triggers the action in the automation if the car charger was providing less then 10 watts (power entity) for over 5 minutes. if not 5 minutes, and then charges over 100 watts from nothing, then do not execute the actions.

How would i go about this?

mighty sphinx
#

You can set up a template or threshold binary sensor that is "on" when the car charger is less than 10W. You can then use the state of that binary sensor in a State condition.

analog walrus
#

But the trigger is if it goes above 100 watts. Then checks conditions. Wont the binary sensor then also flip as its no longer valid (only on below 10 watts)

mighty sphinx
#

The trigger you described was a change in distance past a threshold... post the automation so we don't have to guess what you are actually doing.

analog walrus
#
mode: single
triggers:
  - type: power
    device_id: 3e35d6371c313fec13837692c673e7d6
    entity_id: b828d28c62b6360fc34d821ccf5c9277
    domain: sensor
    above: 950
    trigger: device
conditions:
  - condition: state
    entity_id: timer.car_charging_timer_haos_startup
    state: idle
  - condition: state
    entity_id: binary_sensor.basement_car_charger_below_100_watts
    state: "on"
    for:
      hours: 0
      minutes: 4
      seconds: 0
actions:
  - data:
      target: -6776282582
      message: Car is charging!
    action: telegram_bot.send_message```
unreal owl
#

Can you trigger off the binary sensor changing state rather than using the 950 watts threshold? Because then you could do this

#
description: ""
mode: single
triggers:
  - trigger: state
    entity_id: binary_sensor.basement_car_charger_below_100_watts
    to: 'off'
conditions:
  - condition: state
    entity_id: timer.car_charging_timer_haos_startup
    state: idle
  - condition: template
    value_template: "{{ now() - trigger.from_state.last_changed > timedelta(minutes=4) }}"
actions:
  - data:
      target: -6776282582
      message: Car is charging!
    action: telegram_bot.send_message
analog walrus
#

Thanks, going to try this

analog walrus
#
  - condition: state
    entity_id: timer.car_charging_timer_haos_startup
    state: idle
  - condition: template
    value_template: |-
      - condition: template
          value_template: "{{ now() - trigger.from_state.last_changed > timedelta(minutes=4) }}"
actions:```
#

It says the second condition was not met. Just plugged the car in for the first time today.

unreal owl
#

Post the trace file

unreal owl
#

The trace says the binary sensor was in the off state for only 13 seconds prior to turning on and triggering the automation

#

Check out the history of the binary sensor and see if it is doing what you expect

#

But as far as I can tell, the automation is doing exactly what you requested it to do

analog walrus
#

I see. There's a tiny spike of wwtts when the charger connects, then stops, then starts charging for real. Changing the value to 500 watts solved that.
However, the autonation is still not triggering.

#

Besides, the automation should have been executed before that spike as before that, it was out for over that time.

unreal owl
#

I don’t have access to your system so I’m not going to be able to debug it for you. If you want to figure out why it’s not firing, look through your history and find out when you would have expected it to fire. Then see if there is a trace for the automation at that time. If no trace, look harder at the triggers and ask questions about them if you can’t figure it out. Not sure what other advice I can give.

analog walrus
#

Is the code correct? Is there not perhaps a small error in the condition template?

analog walrus
#

When the trigger fires, doesnt that mean that the sensor changed, amd therefore the condition is not met?