Wireless Charging Phone not recognised

I’m trying to create a simple automation that turns off certain devices when my phone is placed on a wireless charger.

For some reason the below code doesn’t work. Also, when I place my phone on a wireless charger the state in Developer Tools still shows state as ‘Not Charging’.

Am I missing something? Or is it not possible when charging wirelessly?


- id: '1599580459864'
  alias: Bedtime Secure
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.iphone_pro_max_battery_state
    from: not_charging
    to: charging
  condition: []
  action:
  - delay: '00:01:00'
  - scene: scene.secure_all_off
  mode: 

I use this trigger :

{{is_state_attr('sensor.pixel_3_battery_state', 'charger_type', 'wireless')}}

Where would I place that in my code?

Here’s my automation :

- id: '1595330718111'
  alias: Turn off Bedroom Lights if phone charging
  description: ''
  trigger:
  - platform: template
    value_template: '{{is_state_attr(''sensor.pixel_3_battery_state'', ''charger_type'',
      ''wireless'')}}'
  condition:
  - condition: and
    conditions:
    - condition: device
      device_id: 0da2f43299264982a4a2b886404db6e8
      domain: switch
      entity_id: switch.tasmota_upstairs_left_tasmota_upstairs_left
      type: is_on
    - condition: device
      device_id: 8a3216f96367488e8602080b7d7f7013
      domain: switch
      entity_id: switch.tasmota_upstairs_right_tasmota_upstairs_right
      type: is_on
    - condition: template
      value_template: '{{as_timestamp(now()) - as_timestamp(states.script.goodnight.attributes.last_triggered)|
        int <= 3600}}'
  action:
  - data: {}
    service: script.sleep_time
  mode: single
1 Like

Ah, ok, I’ve not worked with templates yet. I’ll have a look at incorporating it.

Thanks

No problem - works 100% :slight_smile:

Thanks. Just looked at the Template section and it looks complicated. It may take me a while :grimacing:

Just replace your trigger with this in your YAML

 trigger:
  - platform: template
    value_template: '{{is_state_attr(''sensor.iphone_pro_max_battery_state'', ''charger_type'',
      ''wireless'')}}'

Or select TEMPLATE as the trigger in the UI and paste this in

{{is_state_attr('sensor.iphone_pro_max_battery_state', 'charger_type', 'wireless')}}

So I have the below now but it still doesn’t work. Sorry for being thick but I’m on a very steep learning curve :grimacing:


- id: '1599580459864'
  alias: Bedtime Secure
  description: ''
  trigger:
  - platform: template
    value_template: '{{is_state_attr(''sensor.iphone_pro_max_battery_state'', ''charger_type'',
      ''wireless'')}}'
  condition: []
  action:
  - delay: 00:01:00
  - scene: scene.secure_all_off
  mode: single

Hmm … I wonder if it’s the iPhone app … I am using android. Check in the developer tools what the charger_type changes to when you stick on to charge …

Ok, so this is odd. I’ve placed the phone on both wireless and wired charger and the state in dev tools continues to show ‘Not Charging’.

I’ve restarted HA and rebooted but the state still says the same regardless of whether it’s physically charging or not.

After some investigation it appears that to obtain the battery state I need to push the location to HA. This, apparently can be done by simply opening the companion app on my phone.

That defeats the object of wanting the automation to run simply by setting the device on the charger.

Is there a way I can solve this by making changes or additions to my automation code?

First post! If this helps anyone, this worked for me. (Android)

In automation UI use trigger type template and paste in the following:

{{ is_state(‘sensor.sm_g998b_charger_type’, ‘wireless’) }}

You will need to substitute ‘sensor.sm_g998b_charger_type’ for your entity I.d.