Support on routine ... thanks!

Good evening,

Very new to Home Assistant and trying to set up a routine where the battery level of my tablet triggers an action. For the moment, it does not seem to work … it only triggers on manually and does not follow the trigger off condition.
Please see the code below :.

alias: Battery Charger S8+ (30%)
description: Battery Charger on if S8+ is below 30%
triggers:
  - type: battery_level
    device_id: f7fd5ca20b2f7066e0ec6839fc620cce
    entity_id: efc6e519be57a0d9348814b836388d69
    domain: sensor
    trigger: device
    below: 35
conditions: []
actions:
  - type: turn_on
    device_id: 6ebd0fa7db44bcdc524c509e4ddfe095
    entity_id: be1925e75ae69c14ad74df78dd5e46cf
    domain: switch
  - wait_for_trigger:
      - type: battery_level
        device_id: f7fd5ca20b2f7066e0ec6839fc620cce
        entity_id: efc6e519be57a0d9348814b836388d69
        domain: sensor
        trigger: device
        above: 90
  - type: turn_off
    device_id: 6ebd0fa7db44bcdc524c509e4ddfe095
    entity_id: be1925e75ae69c14ad74df78dd5e46cf
    domain: switch
mode: single

</>

The idea is that if the battery level falls below 30%, the charger plug activates and turns off when the tablet reaches 90%. As mentioned, newbie working with the UI hence sorry if this issue seems to basic to post.

Thanks !!!

Please post your code as preformatted text (</> in the cogwheel menu). This allows other people to copy it and try it out.

It’s not a good idea to have automations running for more than a minute or two, so I’d suggest either two automations, one for on and one for off, or two triggers with a choose action depending on which one fires.

triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.your_battery_level
    below: 30
    id: below 30
  - trigger: numeric_state
    entity_id:
      - sensor.your_battery_level
    above: 90
    id: above 90
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - below 30
        sequence:
          - action: switch.turn_on
            target:
              entity_id: switch.your_switch
      - conditions:
          - condition: trigger
            id:
              - above 90
        sequence:
          - action: switch.turn_off
            target:
              entity_id: switch.your_switch

All done in the UI! :smile:

Edit: If you can’t get the preformatted text button to work, you can put three backticks before and after the text to be formatted - usually on the key next to the 1. There’s a post about it here:

1 Like

Thanks for the support !
I have corrected the post as per the rules and regulations.
As I posted this yesterday from a tablet, the “cog wheel” was not a function that was available to me.

Hi Profile - KrisM - Home Assistant Community,

It is possible that you may be running into this…

Thanks for the update.

I was a bit too early with my announcement that it works. It still does not !
It seems that my tablet is not “sending” the battery status for Home Assistant to pick up. When I manually start the routine, the routine stops at 90% but it does not seem to want to start when the battery goes below x %
Scratching my head but not really understanding why …

I have the following 2 routines now :

alias: Battery Charger S8+ (30%)
description: Battery Charger on if S8+ is below 30%
triggers:
  - type: battery_level
    device_id: f7fd5ca20b2f7066e0ec6839fc620cce
    entity_id: efc6e519be57a0d9348814b836388d69
    domain: sensor
    trigger: device
    below: 35
conditions: []
actions:
  - type: turn_on
    device_id: 6ebd0fa7db44bcdc524c509e4ddfe095
    entity_id: be1925e75ae69c14ad74df78dd5e46cf
    domain: switch
mode: single

And then one to shut off automatically

alias: Battery Charger OFF at S8+ 80%
description: Battery Charger on if S8+ is below 30%
triggers:
  - type: battery_level
    device_id: f7fd5ca20b2f7066e0ec6839fc620cce
    entity_id: efc6e519be57a0d9348814b836388d69
    domain: sensor
    trigger: device
    above: 80
conditions: []
actions:
  - type: turn_off
    device_id: 6ebd0fa7db44bcdc524c509e4ddfe095
    entity_id: be1925e75ae69c14ad74df78dd5e46cf
    domain: switch
mode: single

What does the battery level sensor look like?
Like this?

No … it seems to remain a stable line … which is not correct.

image

Well then that is your first issue to sort out.
Try disabling the sensor in the app and turn it on again see if that helps

Understood … will try to find how to do that.
Appreciate you putting me on the right track !