Automation Help with Triggers

I’m very new to HA and learning as I go along.
I want an automation to charge my tablet when the battery level reaches 40% and stop when it gets to 80% using a wall plug.
I wrote this but can’t get it to execute.
I can’t see what I’ve done wrong.
Pretty sure it’s right in from of me but don’t see it.
I’m trying to use trigger ID’s as they’re new to me in automations.
Suggestions / corrections?

alias: Fire Tablet Battery Charging
description: “”
trigger:

  • platform: numeric_state
    entity_id:
    • sensor.firetablet_battery_level
      id: BatteryOver
      above: 80
      below: 100
  • platform: numeric_state
    entity_id:
    • sensor.firetablet_battery_level
      id: BatteryUnder
      below: 40
      above: 0
      condition: []
      action:
  • choose:
    • conditions:
      • condition: trigger
        id:
        • BatteryOver
          sequence:
      • type: turn_off
        device_id: 31a74ef23ea5a80fdabfe2d6bf7ecc96
        entity_id: 221bc55632dc472cf99c583c06b8d528
        domain: switch
    • conditions:
      • condition: trigger
        id:
        • BatteryUnder
          sequence:
      • type: turn_on
        device_id: 31a74ef23ea5a80fdabfe2d6bf7ecc96
        entity_id: 221bc55632dc472cf99c583c06b8d528
        domain: switch
        mode: single

Can you format your code?

alias: Fire Tablet Battery Charging
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.firetablet_battery_level
    id: BatteryOver
    above: 80
    below: 100
  - platform: numeric_state
    entity_id:
      - sensor.firetablet_battery_level
    id: BatteryUnder
    below: 40
    above: 0
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - BatteryOver
        sequence:
          - type: turn_off
            device_id: 31a74ef23ea5a80fdabfe2d6bf7ecc96
            entity_id: 221bc55632dc472cf99c583c06b8d528
            domain: switch
      - conditions:
          - condition: trigger
            id:
              - BatteryUnder
        sequence:
          - type: turn_on
            device_id: 31a74ef23ea5a80fdabfe2d6bf7ecc96
            entity_id: 221bc55632dc472cf99c583c06b8d528
            domain: switch
mode: single

OK, your actions don’t look right to me - especially your entity_ids which should be in the format switch.name.

try this…

alias: Fire Tablet Battery Charging
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.firetablet_battery_level
    id: BatteryOver
    above: 80
  - platform: numeric_state
    entity_id: sensor.firetablet_battery_level
    id: BatteryUnder
    below: 40
action:
  - choose:
      - conditions:
          - condition: trigger
            id: BatteryOver
        sequence:
          - service: switch.turn_off
            target:
              entity_id: switch.<your switch's name>
      - conditions:
          - condition: trigger
            id: BatteryUnder
        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.<your switch's name>
mode: single

You will need to rename switch.<your switch's name> for both sequences. You can find out your device’s name in Settings > Devices and Services > Entities.

I removed the device_id and changed the entity_id to the friendly name and get this error trying to save the changes: Message malformed: Unable to determine action @ data[‘action’][0][‘choose’][0][‘sequence’][0]

action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - BatteryOver
        sequence:
          - type: turn_off
            entity_id: switch.smart_plug_mini_2_socket_1
            domain: switch
      - conditions:
          - condition: trigger
            id:
              - BatteryUnder
        sequence:
          - type: turn_on
            entity_id: switch.smart_plug_mini_2_socket_1
            domain: switch

Under the original code, the visual editor shows the correct plug. Just as an FYI
I should note that the battery level sensor is coming from fully kiosk browser.

        sequence:
          - type: turn_off
            entity_id: switch.smart_plug_mini_2_socket_1
            domain: switch

I don’t think this will work. Notice how I changed it in my version to:

        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.<your switch's name>

The entity_id and friendly_name are not the same thing although they will appear similar. Having written that, your format looks good (entity_id’s will use underscores _ instead of spaces.

It looks like it is working using the original code.
I power cycled HA and the tablet.
Maybe something wasn’t reporting correctly.
So far so good.
Thx

great!

Are you using the UI? …I ask as, if you are using yaml, switch.turn_off and switch.turn_on are so much easier to use as you done’t need those long device_ids.