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.
In case anyone else comes across this older thread - the reason that the OP’s conditions were being ignored is because he was using the call service of automation.trigger.
If you want the conditions to be respected, use call service of automation.turn_on.
I was struggling with this as well, did some experimentation, and came up with this.
automation.turn_on is used to enable an automation, not to trigger it. Docs explain that.
automation_trigger can be called with skip_conditions: false if you want to obey the conditions section (as was mentioned earlier in this thread, and also in the aforementioned docs).
But the correct solution is to use a script instead of an automation. A script is just an automation without triggers. And from the iOS shortcut, you would use the “run script” option rather than the “trigger automation” option.