Calculate on time and control a wall plug

Hi,
I have trouble to solve this problem.
I would like to control a wall plug on/off of a calculated on time for my laptop, i.e when the laptop has been on for 3 hours switch on the wall plug and charge the laptop for 1 hour then turn off the wall plug and stop charging the laptop. Restart the time calculation for the laptop on time and so…
In that way I don’t need to bother about the laptop charger be on all the time.
I have to laptop in the same place all the time.

Is this automation best to do in Home Assistant or Node red ?

//Fredrik

It’s pretty simple to do with a few automations and a timer.

  1. trigger - laptop on. action - start a 3 hour timer.
  2. trigger - timer expired. action - turn on wall plug.
  3. trigger - wall plug on for 1 hour. action - turn off wall plug and start timer.
  4. trigger - laptop off. action - stop timer.

Having said that most modern laptops have energy management that cycles the laptop battery between 90% and 20% SOC if left plugged in. So this may not be needed.

Yes, maybe this function already exist in a new laptop.
But I what to learn me more about HA. So I try to get this to work any way.

Do you mean i HA or node red?
I would like to do it in node red, I’m new to it and would like to learn me.
Can you give me some example.

BR, Fredrik

I don’t use Node Red.

Okey,
But can you give me some more exampels how this is done in HA.
I mean code exampels.

/Fredrik

These are all basic automations. There are some examples here:

https://www.home-assistant.io/docs/automation/examples/

and here:

Have a go yourself. If you cant get it to work using the outlines of what I wrote here:

Post what you come up with (correctly formatted) and we’ll go from there.

Hi tom_I,
When I look on the Timer example it seems to restart each time the input goes high. I would rather like to calculate the total on time for the laptop. I.e the laptop can be turn on and off several times before it has to be charged.
And when the laptop has been on for total 3h the wall plug should be turned on and the timer should be reseted.
Do you know to make such timer function?

//Fredrik

Your best be would be to use this sensor to accumulate laptop on time and trigger the charger when it reached 3 hours.