Check how reliable the reporting of this sensor is first sensor.your_phone_name_battery_state. I find that it takes ages to update the charging state sensor for my phone, if it gets updated at all.
If you see a consistent and reliably punctual update of the sensor then it is just a matter of triggering an automation on this sensor state.
trigger:
- platform: state
entity_id: sensor.your_phone_name_battery_state
from: 'Not Charging'
to: 'Charging'
You may want to include a time condition so it only triggers, say, after 9pm. Otherwise it will trigger if you charge your phone during the day.
I’m using the “When turning Do Not Disturb on” automation from Shortcuts and triggering an Home Assistant Call Service a Dictionary shortcut property that contains entity_id: automation.name_of_automation and then passing this dictionary to Call automation.trigger with data.
I guess you can do the same with the “Charger → Is Connected” automation from Shortcuts.
condition: time
after: ‘22:00’
before: 01:00
I believe either ‘01:00’ or 22:00 is needed to make it work. My guess without testing is ‘01:00’.
Having the condition dependcy in the automation means no duplication of functionality and if triggered by another means within HA it will still perform as expected.