Page 1 of 1

Domoticz current state - toggle switches after power supply down

Posted: Wednesday 13 December 2017 15:27
by zefranc
Hello guys,

I been trying to create a python script to toggle my switches status whenever there is a power outage.

I have several chacon outlets controlled by an RFX433 device. Whenver there is a power outage at my home and the power is then restabilished, these switches remain off.
My domoticz is supplied by an UPS and I have a relay powered by a normal supply for which I created a switch to know if the power is ON or OFF.

My idea is to activate a python switch whenever the power is restabished by toggling the status of my switches 2 times to bring the outlets to their previous state.

I tried running some scripts using json but without success. I didn't want to be running "curl" commands on my script.

Has anyone run/developed something like this ?

Regards,

Re: Domoticz current state - toggle switches after power supply down

Posted: Tuesday 19 December 2017 18:45
by zefranc
Since no help was available, please check how I did it :

import os
import sys
import csv
import time
import datetime
from shutil import move
from datetime import date, timedelta
import urllib2
import json
import subprocess

def main():
switches = ["79","80","110","109","108","42","78","44"]
i=0
FNULL = open(os.devnull, 'w')
while i<len(switches):
print(switches)
subprocess.call(["/usr/bin/curl", "-s",
"http://USERNAME:PASSWORD@DOMOTICZ_IP_ADDRESS:PORT/json.htm?type=command&param=switchlight&idx=" + switches +"&switchcmd=Toggle"])
time.sleep(2)


subprocess.call(["/usr/bin/curl", "-s",
"http://USERNAME:PASSWORD@DOMOTICZ_IP_ADDRESS:PORT/json.htm?type=command&param=switchlight&idx=" + switches +"&switchcmd=Toggle"])
time.sleep(2)
i+=1

main ()