I ride an electric bike into work monday-friday.
It has enough charge for two trips, so tuesday evening and thursday evening it needs to be charged, or I’ll run out of charge on the next journey.
The charger is connected to a power monitoring plug so I have stats for when the charge is pulling electricity from the grid and charging my bikes battery, like so:-
I’d like to create an automation that reminds me to charge the battery if its not been charged within the last 48 hours, and for that reminder to only happen hourly from 7pm until 10pm, or stop when its detected I’ve actually started the charging process.
The time based trigger part is pretty straightforward, but I’m not sure how to construct a template condition to only notify me if there has been no charging (charging is defined as the smart plug recording more than 30 watts of power on the smart plug entity sensor.tuya_plug_bike_charger_active_power for at least 10 minutes (but could be more) and then dropping to 0 watts) in the last (say) 30 hours.
I would set an input datetime with {{ (now() + timedelta(days= 2)).replace(hour=17, minute=0, second=0}} when the charge starts.
This should mean you get a datetime with two days ahead at 17:00.
This could then be used as a trigger to remind you.
Thats a neat solution, and this is the automation I’ve used to generate that date time:-
alias: Set Bike Last Charged Date and Time
description: ""
triggers:
- trigger: numeric_state
entity_id:
- sensor.tuya_plug_bike_charger_active_power
for:
hours: 0
minutes: 1
seconds: 0
above: 30
conditions: []
actions:
- wait_for_trigger:
- trigger: numeric_state
entity_id: []
for:
hours: 0
minutes: 1
seconds: 0
below: 1
- action: input_datetime.set_datetime
metadata: {}
data:
datetime: "{{ (now() + timedelta(days= 2)).replace(hour=17, minute=0, second=0)}}"
target:
entity_id: input_datetime.bike_charging_finished
mode: single
It works, its just vulnerable if HA restarts between the active power being detected above 30, and when it drops below 1, this could be 2-3 hours. I can live with it, but was curious if there was a better way ?
I guess I could split out charging starting and ending into separate automations, with a boolean to tell me which state they were in…
There is no entity id in your wait for trigger.
But either way, there is no need for that.
When you put it on charge, that is a good enough trigger.
If you think it’s not, then just change the trigger to below 1 in the trigger part of the automation.
It will not trigger if the state is below 0, it hs to be above 1 then drop below 0 for it to trigger which can only happen if the battery is on charge and the smart plug is on.
And also just keep in mind your description and entity naming is very confusing.
It’s not… it’s setting the time it will remind you next time to charge the battery (in two days at 17:00)
No… bike next charge reminder.
But if you want it to be charging finished then it should only be {{now()}}
yeah I pasted it too soon.
I wanted really to have the date of the next charge be set once the last charge had finished, rather than started.
It will not trigger if the state is below 0, it hs to be above 1 then drop below 0 for it to trigger which can only happen if the battery is on charge and the smart plug is on.
Ofc!
And agreed on the entity names, I changed them afterwards as well, it is now ‘bike charge next due’
If you want a reminder every hour as you said before then you can trigger on the datetime.
Choose or if then: smart plug == 0, set new datetime one hour ahead and notify.
Yes
But with a choose you can make sure it nags on you if you have not set it on charge, and then keeps quiet if you did good.
I’m currently in bed but I can do it for you tomorrow.
But you need to use a choose, where if the bike is on charge, you can set the time 3 or 4 hours ahead because the other automation above will set it to two days ahead later anyways before this time has been reached.
But if you have not placed the bike on charge you set the time one hour ahead using {{ now() + timedelta(hours = 1) }}.
This will then trigger the same automation again and notify that you have not yet put the bike on charge.
You don’t need the offset solution.
The offset solution will also trigger and tell you to set the bike on charge even when it already is on charge
Interested to see how that might work, even just for my continued learning, otherwise I could also just use the above approach, but put a condition in not to notify me if the active power entity is above 1 (i.e. charging)
Oh… I just realized the default will catch if the smart plug is unavailable.
You probably should add a second condition option in the choose if smart plug is > 1 then +4 hours.
And default is send error message to phone
I just realized you need a condition here also.
If the smart plug goes unavailable then goes to 0 then this will trigger.
You need to add a condition with not_from: unavailable/unknown.