Use iCloud to automate night scene

Hi folks,

I wanted HA to set a night scene when I plug my phone in the charger at night. This is inspired by another user who is doing this by reading the power-draw of a z-wave power plug. I don’t have z-wave jet, so I chose to use what I already had - iCloud.

This is a simple little automation that activates a night scene using the battery_status attribute in the iCloud component (or specifically in my usecase changes my status to activate a night scene.)

- alias: 'Set Sleep status when battery is charging + night + home'
  trigger:
    platform: template
    value_template: "{{ is_state_attr('device_tracker.iphone', 'battery_status', 'Charging') }}"
  condition:
    condition: and
    conditions:
      - condition: time
        after: '21:00:00'
        before: '05:00:00'
      - condition: state
        entity_id: device_tracker.iphone
        state: 'Home'
      action:
        - service: input_select.select_option
          data:
            entity_id: input_select.michael_status
            option: 'Sleeping'

This solution is not instant like a z-wave device would be. However my night scene is just turning off lights and powerplugs so i have no problem with a slight 10-20 min delay.

1 Like

Hi,

I have ben thinking of something like that but never taught about this solution. I am using the iOs app so I already have a sensor called sensor.iphone_7_plus_battery_state, I will use that one as a trigger!

Thanks for sharing!

1 Like

Pleasure is mine. I like to come up with these little tweaks.

I don’t use the HA app myself, and there is not much information on the app store (or HA page for that matter), could you tell me what sensors it gives you?

1 Like

I have one device and two sensors

device_tracker.iphone_7_plus that tells me if I’m home or not_home (or in a zone)

sensor.iphone_7_plus_battery_level says the percentage of the battery

sensor.iphone_7_plus_battery_state if the phone is unplugged och charging

1 Like