Computer on and Not Home

I have a few desktop pc’s in the house. These do not run HA.
I sometimes forget to turn them off if I am going out.

All of them are connected to a plug that monitors power.

I want to create an automation that will notify me if I leave home and the power is still on.

Since the power is moitored I created an automation that does not work, in that it does not notify me if I am not home and the pc is on.

Here is the code I have.

- id: "d40864b1-32d5-4f04-a437-d8e18846afda"
  alias: Blackbox On When leaving
  description: 'Blackbox On When leaving'
  trigger:
  - type: power
    platform: device
    device_id: 84b18a2418226c0311f6649fe37ba389
    entity_id: sensor.office_power_amie_blackbox_power
    domain: sensor
    above: 20
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: "{{ states('person.carlton_brooks') != 'home' }}"   
  action:
    - service: notify.telegram
      data:
        message: "BLACKBOX ON and you are NOT HOME as of {{ now().strftime('%A, %B %d, %Y %I:%M:%S %p') }}"
  mode: single   

What might I need to change to make this work.
Thank you.

Your power sensor would have to go from below 20 to above 20 to trigger that - does that happen? I would have expected the computer to draw a steady amount.

Hi Carlton

  1. conditions are always AND + you have only one
  2. as @Stiltjack says, the automation will only run if the power goes from below 20 to above it
  3. your trigger should be if you leave home and your pc draws over 20 watt is the condition
  4. I’m not sure if this is possible but I think it is: create a shell script to power your pc down/put into sleep will make your automation even more advanced
1 Like

Why not ping the PC, rather than using the power monitoring plug?

Then the trigger would be you leaving home, as @Nick4 says, and the result of the ping would be the condition.

There is an add-on which will shut down Windows PCs:

Hasn’t been updated recently, but it still seems to work. The PC you’re shutting down doesn’t need to be on HA.

1 Like

You’ve it just the wrong way round. :wink:

The trigger needs to be the change from “home” to “not home”. Then you check in the condition for the value to be above 20.

You are confusing trigger and condition. :slight_smile: Happens to the best! :smiley:

A trigger is something, that reacts to a change. In case of your posted script, it triggers in that one moment, where your power usage crosses the value of 20.

A condition is to check for a specific value, in that moment. Something triggers the automation and in that moment, a condition checks, if the criteria is met. Let’s say, your condition is like this:

- condition: state
  entity_id: sensor.power
  above: 20

That would mean, in the moment of the check, the value needs to be above 20. Doesn’t matter, if it’s 20, 25 or even 200, above 20 is above 20.

A condition is only to check a value in the moment the automation is triggered. A trigger is always to check, if a moving value passes a treshold. :slight_smile:

1 Like

To make it robust, I’d use matching triggers and conditions. 2 triggers: when you leave home and when the power goes above 20. 2 conditions: you are away from home and the power is above 20.

This way you get notified in 2 scenarios:

  • if you leave home and the power is already above 20
  • if you are already away from home and the power increases above 20

I would also agree that ping is probably more robust, and you can still do matching triggers & conditions when you replace the power plug with ping.

To me, this doesn’t look as automation. It seems you want the PC’s to go off when not home. Automation would be if ‘the home’ detects you are not home and then switches the PC’s off. I would see then HA more as a burden, not as a help.

As already said, you could use ping and some tool to shutdown. I only use Linux PC’s and use basically ping to determine ‘ON’ state and a remote command ‘systemctl suspend’ to actively lower the power consumption.

But much more important, I have configured power management of the PC’s such that they go off by themselves if no activity. You can choose which state, even hibernate, but not really cutting the last standby 1 Watt or so, but that you can save maybe by removing the power monitoring device as that also always uses 1 Watt or so usually. A modern PC can monitor/report its own power mostly, so I would use that method.
But note that the bigger (fan equipped) PC power supplies are not very efficient in the lower regions, so cutting the power might be the only solution to get below 1 Watt.

To turn on, you can use Wake-on-LAN if RJ45 network connected, but maybe they only have WiFi. Or just touch the keyboard or power/sleep button if you are home.

I monitor the power of my NAS PC (12V power monitoring) and it turns out that over time (hours/days) the power consumption is very predictable. From another ‘fat’ PC, I also monitored it for a week and more or less same story, although under max load uses way more power than the almost always idle state.