Automate switch restart based on wattage - Wemo Insight

I have searched and seen some topics about this, but couldn’t make it work for my scenario.

I have an Ethereum miner connected to a Wemo switch. When it freezes the wattage drops to about 350. So, I want the switch to turn off, sleep 30, turn on when wattage drops below 400 for 30 seconds.

I’ve made an automation in the GUI. The condition and action was easy, but I have problems with the trigger. I’ve figured I need to create a template, but I don’t understand how and how I include it in the automation. So that’s what I need help with =)

Dev Tools States:

switch.wemo_insight

current_power_w: 850.745
today_energy_kwh: 20.51
state_detail: on
on_latest_time: 01d 13h 10m 58s
on_today_time: 01d 00h 00m 00s
on_total_time: 13d 12h 40m 37s
power_threshold_w: 8
friendly_name: Miner

I’d use a numeric_state trigger. The example in the docs is quite similar to what you want. In your case you’d want it to be something like this:

automation:
  trigger:
	platform: numeric_state
	entity_id: switch.wemo_insight
	value_template: '{{ state.attributes.current_power_w }}'
	below: 400
	for:
	  seconds: 30

Is it healthy for your rig to cycle power that way? Also, what is the power draw like during the restart/boot-up window? You have to be careful that it’s not under 400 watts, because then you might get in an endless wemo bootloop. Consider increasing the time limit under for: .

That looks like what I want, yes. I tried the same, but without the value_template :stuck_out_tongue:

Yes, it’s safe to do this. And 30 sec is just enough to reboot and start the miner program (850w).
However, if it doesn’t manage to start the program and gets stuck in a loop it would probably not turn on at all after a few cycles due to over charged capacitors. I will have to try and find the optimal time, for sure. I’ve configured it to email me when it freezes as well, so I can reboot it manually, so this is just to save me some hours if it freezes during the night.

I’ve configured the trigger, and will test during the day!

As a note, I did similar except I wrote a script that scrapes my hash rate from my pool. If it is below a threshold for a period of time I send a push notification. I have debated just adding the outlet and then power cycling from that same automation. I didn’t know the Demo smart plugs provide power usage. That would be great to track for mining rigs for sure. I currently use a Kill-A-Watt for calculating power usage.