Strange automation problem

Hi folks,

I have a strange problem with an automation, which doesn’t want to work.

It worked some weeks ago…

I have two automations to switch al wall-plug-switch.

First automation to switch off works quiet well
Second automation to switch on doesn’t want to

automation 1:

alias: Pixel 6 Pro nicht mehr laden
description: ""
trigger:
  - platform: state
    entity_id: sensor.pixel_6_pro_battery_level
    to: "100"
condition:
  - condition: device
    device_id: 46957dc47dfea5408c388f7023ddabff
    domain: device_tracker
    entity_id: device_tracker.pixel_6_pro_mob
    type: is_home
action:
  - type: turn_off
    device_id: c5f8056df730dd58c5577a0e4e5f6edc
    entity_id: 55c78561997a22dcb7db713ccad0f733
    domain: switch
mode: single

automation 2:

alias: Pixel 6 Pro laden
description: ""
trigger:
  - platform: time_pattern
    minutes: /5
condition:
  - condition: state
    entity_id: device_tracker.pixel_6_pro_mob
    state: home
  - condition: numeric_state
    entity_id: sensor.pixel_6_pro_battery_level
    below: 90
action:
  - type: turn_on
    device_id: c5f8056df730dd58c5577a0e4e5f6edc
    entity_id: 55c78561997a22dcb7db713ccad0f733
    domain: switch
mode: parallel
max: 10

first I tried single mode on automation 2, but got error: Stopped because only a single execution is allowed
so i tried parallel mode.
Now I get the error: <unknown entity> einschalten

The entity-switch works quiet well.

What ist the problem?

I know this article and followed allready all instructions.
Your hint doesn’t solve my problem.

Have you read what I wrote? :thinking:

I configured a second trigger.
A boolean switch.
When I use this switch the trigger reacts in the automation view but nothing else happens.

I allready made an new automaion an deleted the old one.
No effect

And yes I did read your post. Nowhere did you mention that you had inspected the automation trace. So where is your automation trace?

Does it matter that in the 1st automation you are testing sensor.pixel_6_pro_battery_level as a string and the 2nd automation you are testing sensor.pixel_6_pro_battery_level as a number ?

Trace would be helpful.
In your first automation you are using the
is_home condition in the second automation you are using home. This doesn’t look right to me.

after setting mode to parallel:

sooner traces are gone

You can use a single automation to control the wall plug.

alias: Pixel 6 Pro 
description: ""
trigger:
  - id: 'off'
    platform: state
    entity_id: sensor.pixel_6_pro_battery_level
    to: "100"
  - id: 'on'
    platform: numeric_state
    entity_id: sensor.pixel_6_pro_battery_level
    below: 90
condition:
  - condition: state
    entity_id: device_tracker.pixel_6_pro_mob
    state: home
action:
  - service: 'switch.turn_{{ trigger.id }}'
    target:
      entity_id: switch.your_wall_plug
mode: single

Replace switch.your_wall_plug with the entity_id of your actual wall plug.

What are you trying to do exactly with this automation?
I dropped using two automations for turning something on or off because I find it unreliable. I use single automation with choose actions and helpers as needed to restart some counters.

when the battery crosses 90, it turns on the plug as long as your device is home. When your device reaches 100, it turns on the plug.

How often does HA check the battery_level?

when the battery level changes. Your tiggers will only fire when your battery level is equal to 100 or when it crosses the threshold from above 90 to below 90. It will not trigger if your already below 90 and it moves further below 90.

It works exactly the way petro explained. Let me know if you want it to work differently.

that’s what I thought.
So 123 solution is worthless

I think I’ll try this

alias: Pixel 6 Pro - Ladegerät
description: ""
trigger:
  - platform: time_pattern
    minutes: /5
condition:
  - condition: state
    entity_id: device_tracker.pixel_6_pro_mob
    state: home
action:
  - if:
      - condition: state
        entity_id: sensor.pixel_6_pro_battery_level
        state: "100"
    then:
      - service: switch.turn_off
        data: {}
        target:
          entity_id: switch.ladegerat
  - if:
      - condition: numeric_state
        entity_id: sensor.pixel_6_pro_battery_level
        below: 90
    then:
      - service: switch.turn_on
        data: {}
        target:
          entity_id: switch.ladegerat

Try this version and let me know if it fulfills your requirements. The trigger continuously monitors the states of all three entities (sensor, switch, and device_tracker). In other words, not at a fixed polling rate of every 5 minutes like in your version, but at the very instant when any of the three entities changes value.

alias: Pixel 6 Pro 
description: ""
trigger:
  - platform: template
    value_template: >
      {% set bl = states('sensor.pixel_6_pro_battery_level') | int(0) %}
      {% set sw = states('switch.ladegerat') %}
      {{ (bl == 100 and sw == 'on') or (bl <= 90 and sw == 'off') 
        and is_state('device_tracker.pixel_6_pro_mob', 'home') }}
condition: []
action:
  - service: "switch.turn_{{ 'on' if states('sensor.pixel_6_pro_battery_level') | int(0) < 90 else 'off' }}"
    target:
      entity_id: switch.ladegerat
mode: single
max_exceeded: silent

I’ll try.
It looks quiet elegant.
Is there anywhere a tutorial to learn that template programming stuff?

1 Like

I think I’m probably too stupid for this. :cry: