Hello, I would like to make my Emporia smart plug restart if it falls outside of a predetermined wattage range for a certain amount of time. For example, let’s say my target wattage is 1000W. If the power goes above 1200W for 1 min or more, or if it goes below 800W for 5 minutes or more, I would like for it to turn off for a minute and then turn back on. The logic would be something like this in python:
target_power = 1000
buffer = 200
power = plug1.power()
if (average(power[-60:]) >= target_power + buffer || average(power[-300:]) <= target_power – buffer):
shutdown(plug1)
wait(15s)
shutdown(plug2)
wait(30s)
turn_on(plug2)
wait(30s)
turn_on(plug1)