Toggle Switch based on battery level - On works, Off Doesn't?

Hi, I have created two Automations to toggle the power supply to my kitchen Home Assistant tablet - the aim was to extend the battery life over simply charging 24/7 at 100%. My issue is the automation to switch the smart switch on at 20% works, but bizarrely a similar automation to switch off at 80% doesn’t. Completely stumped and welcome some pointers!

Automation to switch on at 20% (works fine):

alias: Kitchen Tablet On at 20%
description: Kitchen tablet will turn on power switch at 20%
trigger:

  • platform: state
    entity_id:
    • sensor.kitchenfirehd_battery_level
      to: “20”
      from: null
      condition: []
      action:
  • service: switch.turn_on
    entity_id: switch.kitchen_display_tablet_socket
  • service: notify.mobile_app_rmx3393
    data:
    message: Home Assistant tablet power switch on as battery is at 20%
    title: Home Assistant tablet power switch on
    mode: single

Automation to switch off at 80% (doesn’t work):

alias: Kitchen Tablet Off at 80%
description: Kitchen tablet will turn off power switch at 80%
trigger:

  • platform: state
    entity_id:
    • sensor.kitchenfirehd_battery_level
      to: “80”
      condition: []
      action:
  • service: switch.turn_off
    data: {}
    target:
    entity_id: switch.kitchen_display_tablet_socket
  • service: notify.mobile_app_rmx3393
    data:
    message: Home Assistant tablet power switch off as battery is at 80%
    title: Home Assistant tablet power switch off
    mode: single

Thank you

You added the Blueprints tag to this in the topic. I suggest removing that as this is not a BP. You will get better eyes on it…

Aside from that, is battery level ever actually exactly 80? Is that a selected number or an actual reading.? If an actual reading you may want to use a template and shut it off when > 80 and turn it on when < 20. Also as written this will only trigger on when it is at exactly 20 and the prior measurement was null, so if it goes from 30 or from 21 down to 20, it will not trigger.

Triggers are VERY literal and logical, be careful what you ask for.

Something like this:

trigger:
  - platform: state
    entity_id: kitchenfirehd_battery_level
condition:
  - condition: numeric_state
    entity_id: sensor.kitchenfirehd_battery_level
    above: 80
1 Like

Also, see #11 here …
How to help us help you - or How to ask a good question - Configuration - Home Assistant Community (home-assistant.io)

Many thanks @Sir_Goodenough Yes it’s too precise, still learning.

1 Like