Do the entities somehow show if they are currently charging?

I’ve set up the very cool battery alert which is slowly populating.
One of the items that has appeared is my youngest cell phone.
I would very much like to create an alert at his bedtime, if he has forgotten to attach it to the charger.
But that would require that I can somehow read if it’s charging, is there any way I can do that, without having to monitor if the % level of the battery is going up?

what phone is he using and how do you track its battery level?
iOS tracks whether the phone is charging or not, not sure about Android.
Some location tracking apps (owntracks, Life360) also provide that info

1 Like

It’s an android Sony Xperia XA2.
I have owntracks installed on the phone, but the state just shows:

{
  "source_type": "gps",
  "latitude": 55.5870645,
  "longitude": 12.289519,
  "gps_accuracy": 800,
  "battery": 48,
  "velocity": 0,
  "tid": "13",
  "friendly_name": "adrian"
}

apologies, been a very long time since I used owntracks.
I use now Life360 which is a lot more accurate and reliable and does provide that info, should you fancy the change.
I’m not aware of any native android app yet that would provide this

1 Like

Ok, I don’t have any preferences, so I’ll give life360 a try.
Do I need to install the files you link to, or the Life360 Device Tracker Platform for Home Assistant ?
So far I’ve taken this latter one, then I hope something pops up.

yeah there is no native HA life360 component so “we’re all” using @pnbruckner’s custom component.
Check his docs to get it installed via Custom Updater and tracker-card.

1 Like

Hmm, after installing the custom component, I get this in the config file:
Your configuration contains extra keys that the platform does not support.
Please remove [device_tracker]…

Other than that, I see the two devices I’ve configured so far, and it does say ‘charging’ that is great!
Thankyou for the hint!

If you can post your configuration that is related to device_tracker we can take a see and look what might be wrong. (Don’t forget to redact any sensitive information.)

FYI, the battery_charging attribute is true when the phone is plugged in and it is not fully charged. At least, that has been my experience with Android phones.

1 Like

Hi there

Ok, this is the relevant part, I’ve cut out some of the settings, as it would get too big:
homeassistant:

  # Name of the location where Home Assistant is running
  name: ---
  # Location required to calculate the time the sun rises and sets
  ---
  ---
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 0
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: Europe/Copenhagen
  # Customization file
  customize: !include customize.yaml
  packages: !include_dir_named packages
 
  auth_mfa_modules:
    - type: totp
    
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

mqtt:
  ---
  
# Show the introduction message on startup.
#introduction:

http:
  ---

custom_updater:
  track:
    - components
    - python_scripts
  component_urls:
    - https://raw.githubusercontent.com/pnbruckner/homeassistant-config/master/custom_components.json
  python_script_urls:
    - https://raw.githubusercontent.com/pnbruckner/homeassistant-config/master/python_scripts.json

nest:
  client_id: !secret nest_client_id
  client_secret: !secret nest_secret

fritzbox:
  devices:
    - ---
      username: !secret fritz_user
      password: !secret fritz_pass

device_tracker:
  - platform: fritz
    username: !secret fritz_user
    password: !secret fritz_pass
    device_tracker:
  - platform: life360
    username: !secret life360_username
    password: !secret life360_password
    max_gps_accuracy: 200
    prefix: life360
    show_as_state: driving, moving, places

For my purpose it is perfect that it says charging until it doesn’t charge.
Our youngest forgets to charge his phone, so when he leaves for the day he gets in trouble because the housekey is a danalock, and the buspass is also on his phone :slight_smile: So I would like to make sure that the phone is charging when he goes to bed, or send a message to him, reminding him of it.

device_tracker:
  - platform: fritz
    username: !secret fritz_user
    password: !secret fritz_pass
    device_tracker:  <----------- REMOVE THIS LINE
  - platform: life360
    username: !secret life360_username
    password: !secret life360_password
    max_gps_accuracy: 200
    prefix: life360
    show_as_state: driving, moving, places
1 Like

doooh, how did I miss that, I’ve looked and looked :smiley:
THANKYOU

1 Like

This is the automation I’ve created, it seems to work:

- alias: Adrians phone is not set in charger
  initial_state: 'on'
  trigger:
    platform: time
    at: '21:30:00'
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: "{{ not states.device_tracker.life360_adrian_fribert.attributes['battery_charging'] }}"
      - condition: time
        weekday:
          - mon
          - tue
          - wed
          - thu
          - sun
  action:
    - service: tts.google_say
      entity_id: ' media_player.faellesomrader'
      data:
        message: "Adrian har glemt at sætte sin telefon til opladning"
        language: 'da

Looks good. But you can simplify it a little. First, when you list multiple conditions the default is to “and” them together, so you don’t have to specify that. Also, you can use attributes.battery_charging instead of attributes['battery_charging']. Actually, it’s probably better to use the is_state_attr function. And lastly, you can enter a list in one line using brackets. So, the condition part of the automation can be simplified to:

  condition:
    - condition: template
      value_template: >
        {{ is_state_attr('device_tracker.life360_adrian_fribert',
                         'battery_charging', false) }}
    - condition: time
      weekday: [mon, tue, wed, thu, sun]
1 Like

Hey, very cool, thanks, I just went through my automations, and modified them, so that saved 40-50 lines :slight_smile:

1 Like