So I have a problem with my computer video cutting out every now and again when i am streaming video and when I’m not home my kids can’t figure out how to get everything back up and running when this happens. So I set up a batch file to load everything back up when the computer starts up but I was hoping with this is would automatically just restart so everything was automated. I know nothing of python coding but I’m willing to learn. I got it to recognize the outlet, just don’t know where to start to get the coding right for this.
You need an automation for this to work. Keep in mind that if you’re not too careful you might end up in a reboot loop and ultimately fry your computer. I’ve seen comments from people using this particular plug with TV sets and frying them.
You should start by reading the whole automation section:
I will definitely keep that in mind as frying my computer is not something I am willing to do. But I pieced together something I think might work. Let me know before I do it if there is anything I am missing, please.
automation:
trigger:
platform: state
entity_id: switch.main_tv
from: is_state_attr(‘switch.main_tv’, ‘Current consumption=’ >400)
to: is_state_attr(‘switch.main_tv’, ‘Current consumption=’ <400)
for:
minutes: 3
action:
service: switch.turn_off
entity_id: switch.main_tv
I wouldn’t cut the power, you are likely to corrupt your OS or run into hardware issues.
Is the computer running windows? You can send a shutdown command from HA.
See below for further info. My repo only shows the shutdown option. Adding -r will make the computer restart after shutdown and a -f flag will force the shutdown.
https://github.com/SilvrrGIT/HomeAssistant/blob/master/shell_commands.yaml
http://prefetch.net/blog/index.php/2009/05/31/shutdown-a-windows-machine-from-the-unix-command-line/
I love the idea, but when the display cuts out it disconnects from everything, including being able to run any commands. So having the computer restart itself won’t work.
I’ve already tried where it would run a batch file with the shutdown/restart command if the display cuts out, but it won’t work. Which means when the display cuts out, I’m pretty sure the computer freezes.
So I’ve been slowly piecing things together to get what I want, but the automation seems to be where I am stuck. It won’t load with this automation and I can’t figure out why.
switch:
- platform: tplink
host: 192.168.0.22
name: main_tv
sensor:
- platform: yr
- platform: template
sensors:
main_tv:
value_template: “{%- if states.switch.main_tv.attributes[‘Current consumption’] | replace(’ W’, ‘’) | float | float > 20 %}on{% else %}off{%- endif %}”
automation:
trigger:
platform: state
entity_id: sensor.main_tv
from: ‘on’
to: ‘off’
for:
minutes: 10
action:
service: switch.turn_off
entity_id: switch.main_tv
delay: ‘00:00:05’
service: switch.turn_on
entity_id: switch.main_tv
It keeps telling me there is a duplicate key “service” and it won’t load. But I don’t see why you can’t call two actions for the same trigger.
And even if I take out the second service call, I get it to load, but I go to the config validation and it has errors there as well.
for action format it like this:
action:
- service: switch.turn_off
entity_id: switch.main_tv
- delay: '00:00:05'
- service: switch.turn_on
entity_id: switch.main_tv
When having multiple triggers or items under action they need to be in a list as noted above. Also in the docs at the bottom of the link below.
Ah that makes sense, I thought it might have something to do with the dashes, but I think when I tried it with them I put them directly before service and then it had a problem with that too.
That shows up perfectly in the frontend and I’m sure it will work wonderfully now. Thank you so very much for your help and prompt replies. I am sure I will be trying to automate nearly everything in my house now.