Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
domotique [2015/06/07 15:41] – madko | domotique [2016/03/21 17:21] (Version actuelle) – [Jeedom sur Raspberry PI 2 ou 3] madko | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | Récuperer les sources et les compiler (pas trop lourd même sur un RPI). | + | ====== Jeedom |
+ | Avec l' | ||
+ | |||
+ | < | ||
+ | pacman -S docker | ||
+ | </ | ||
- | Configuration de tellstick duo pour piloter une prise DIO: | + | Mettre son utilisateur courant dans le groupe docker (pour éviter sudo). |
+ | Utilisation de l' | ||
+ | |||
+ | < | ||
+ | docker pull sbeuzit/ | ||
+ | docker run --name data sbeuzit/ | ||
+ | </ | ||
+ | |||
+ | Cette image ne sert que pour conserver les données. Il faut ensuite un containeur pour la partie MySQL : | ||
+ | |||
+ | < | ||
+ | docker pull hypriot/ | ||
+ | docker run --name jeedom-mysql -e MYSQL_ROOT_PASSWORD=my_mysql_password --volumes-from data -d hypriot/ | ||
+ | </ | ||
+ | |||
+ | Il s'agit de l' | ||
+ | |||
+ | Il ne reste plus qu'à lancer le containeur jeedom avec le lien vers nos containeurs précédents : | ||
+ | |||
+ | < | ||
+ | docker run -d --link jeedom-mysql: | ||
+ | </ | ||
+ | |||
+ | A noter le / | ||
+ | |||
+ | ====== Domoticz sur Raspberry PI B+ ====== | ||
+ | |||
+ | Récuperer les sources et les compiler (pas trop lourd même sur un RPI). | ||
+ | |||
+ | Configuration de tellstick duo pour piloter une prise DIO fichier / | ||
< | < | ||
Ligne 34: | Ligne 68: | ||
} | } | ||
</ | </ | ||
- | |||
Quelques tâches en cron pour les tests sur IP: | Quelques tâches en cron pour les tests sur IP: | ||
+ | < | ||
+ | */10 * * * * / | ||
- | */10 * * * * / | ||
*/10 * * * * / | */10 * * * * / | ||
+ | </ | ||
Et le script check_device_online.py: | Et le script check_device_online.py: | ||
+ | < | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | # Date: 25-02-2015 | ||
+ | # Info: Checks the presence of the given device on the network and reports back to domoticz | ||
+ | # URL : https:// | ||
+ | # | ||
- | # | + | import sys |
- | # Title: check_device_online.py\\ | + | import datetime |
- | # Author: Chopper_Rob\\ | + | import time |
- | # Date: 25-02-2015\\ | + | import os |
- | # Info: Checks the presence of the given device on the network and reports back to domoticz\\ | + | import subprocess |
- | # URL : https:// | + | import urllib2 |
- | # Version : 1.6.2\\ | + | import json |
- | \\ | + | import base64 |
- | import sys\\ | + | |
- | import datetime\\ | + | # Settings for the domoticz server |
- | import time\\ | + | domoticzserver=" |
- | import os\\ | + | domoticzusername = " |
- | import subprocess\\ | + | domoticzpassword = " |
- | import urllib2\\ | + | |
- | import json\\ | + | # If enabled. The script will log to the file _.log |
- | import base64\\ | + | # Logging to file only happens after the check for other instances, before that it only prints to screen. |
- | \\ | + | # |
- | # Settings for the domoticz server\\ | + | log_to_file = True |
- | domoticzserver=" | + | |
- | domoticzusername = " | + | # The script supports two types to check if another instance of the script is running. |
- | domoticzpassword = " | + | # One will use the ps command, but this does not work on all machine (Synology has problems) |
- | \\ | + | # The other option is to create a pid file named _.pid. The script will update the timestamp |
- | # If enabled. The script will log to the file _.log\\ | + | # every interval. If a new instance of the script spawns it will check the age of the pid file. |
- | # Logging to file only happens after the check for other instances, before that it only prints to screen.\\ | + | # If the file doesn' |
- | # | + | # Please chose the option you want to use " |
- | log_to_file = True\\ | + | check_for_instances = " |
- | \\ | + | |
- | # The script supports two types to check if another instance of the script is running.\\ | + | # DO NOT CHANGE BEYOND THIS LINE |
- | # One will use the ps command, but this does not work on all machine (Synology has problems)\\ | + | if len(sys.argv) != 5 : |
- | # The other option is to create a pid file named _.pid. The script will update the timestamp\\ | + | print ("Not enough parameters. Needs %Host %Switchid %Interval %Cooldownperiod." |
- | # every interval. If a new instance of the script spawns it will check the age of the pid file.\\ | + | sys.exit(0) |
- | # If the file doesn' | + | |
- | # Please chose the option you want to use " | + | device=sys.argv[1] |
- | check_for_instances = " | + | switchid=sys.argv[2] |
- | \\ | + | interval=sys.argv[3] |
- | \\ | + | cooldownperiod=sys.argv[4] |
- | \\ | + | previousstate=-1 |
- | # DO NOT CHANGE BEYOND THIS LINE\\ | + | lastsuccess=datetime.datetime.now() |
- | if len(sys.argv) != 5 :\\ | + | lastreported=-1 |
- | print ("Not enough parameters. Needs %Host %Switchid %Interval %Cooldownperiod." | + | # |
- | sys.exit(0)\\ | + | domoticzurl = ' |
- | \\ | + | |
- | device=sys.argv[1]\\ | + | if check_for_instances.lower() == " |
- | switchid=sys.argv[2]\\ | + | pidfile = sys.argv[0] + ' |
- | interval=sys.argv[3]\\ | + | if os.path.isfile( pidfile ): |
- | cooldownperiod=sys.argv[4]\\ | + | print datetime.datetime.now().strftime(" |
- | previousstate=-1\\ | + | if (time.time() - os.path.getmtime(pidfile)) < |
- | lastsuccess=datetime.datetime.now()\\ | + | print datetime.datetime.now().strftime(" |
- | lastreported=-1\\ | + | print datetime.datetime.now().strftime(" |
- | # | + | sys.exit(0) |
- | domoticzurl = ' | + | else: |
- | \\ | + | print datetime.datetime.now().strftime(" |
- | if check_for_instances.lower() == " | + | else: |
- | pidfile = sys.argv[0] + ' | + | open(pidfile, |
- | if os.path.isfile( pidfile ):\\ | + | |
- | print datetime.datetime.now().strftime(" | + | if check_for_instances.lower() == " |
- | if (time.time() - os.path.getmtime(pidfile)) < (float(interval) * 3):\\ | + | if int(subprocess.check_output(' |
- | print datetime.datetime.now().strftime(" | + | print (datetime.datetime.now().strftime(" |
- | print datetime.datetime.now().strftime(" | + | sys.exit(0) |
- | sys.exit(0)\\ | + | |
- | else:\\ | + | def log(message): |
- | print datetime.datetime.now().strftime(" | + | print message |
- | else:\\ | + | if log_to_file == True: |
- | open(pidfile, | + | logfile = open(sys.argv[0] + ' |
- | \\ | + | logfile.write(message + " |
- | if check_for_instances.lower() == " | + | logfile.close() |
- | if int(subprocess.check_output(' | + | |
- | print (datetime.datetime.now().strftime(" | + | def domoticzstatus (): |
- | sys.exit(0)\\ | + | json_object = json.loads(domoticzrequest(domoticzurl)) |
- | \\ | + | status = 0 |
- | def log(message): | + | switchfound = False |
- | print message\\ | + | if json_object[" |
- | if log_to_file == True:\\ | + | for i, v in enumerate(json_object[" |
- | logfile = open(sys.argv[0] + ' | + | if json_object[" |
- | logfile.write(message + "%%\%%n")\\ | + | switchfound = True |
- | logfile.close()\\ | + | if json_object[" |
- | \\ | + | status = 1 |
- | def domoticzstatus ():\\ | + | if json_object[" |
- | json_object = json.loads(domoticzrequest(domoticzurl))\\ | + | status = 0 |
- | status = 0\\ | + | if switchfound == False: print (datetime.datetime.now().strftime(" |
- | switchfound = False\\ | + | return status |
- | if json_object[" | + | |
- | for i, v in enumerate(json_object[" | + | def domoticzrequest (url): |
- | if json_object[" | + | request = urllib2.Request(url) |
- | switchfound = True\\ | + | # |
- | if json_object[" | + | try: |
- | status = 1\\ | + | response = urllib2.urlopen(request) |
- | if json_object[" | + | except: |
- | status = 0\\ | + | print(" |
- | if switchfound == False: print (datetime.datetime.now().strftime(" | + | sys.exit(-1) |
- | return status\\ | + | else: |
- | \\ | + | return response.read() |
- | def domoticzrequest (url):\\ | + | |
- | request = urllib2.Request(url)\\ | + | log (datetime.datetime.now().strftime(" |
- | # | + | |
- | try:\\ | + | lastreported = domoticzstatus() |
- | response = urllib2.urlopen(request)\\ | + | if lastreported == 1 : |
- | except:\\ | + | log (datetime.datetime.now().strftime(" |
- | print(" | + | if lastreported == 0 : |
- | sys.exit(-1)\\ | + | log (datetime.datetime.now().strftime(" |
- | else:\\ | + | |
- | return response.read()\\ | + | while 1==1: |
- | \\ | + | currentstate = subprocess.call(' |
- | log (datetime.datetime.now().strftime(" | + | |
- | \\ | + | if currentstate == 0 : lastsuccess=datetime.datetime.now() |
- | lastreported = domoticzstatus()\\ | + | if currentstate == 0 and currentstate != previousstate and lastreported == 1 : |
- | if lastreported == 1 :\\ | + | log (datetime.datetime.now().strftime(" |
- | log (datetime.datetime.now().strftime(" | + | if currentstate == 0 and currentstate != previousstate and lastreported != 1 : |
- | if lastreported == 0 :\\ | + | if domoticzstatus() == 0 : |
- | log (datetime.datetime.now().strftime(" | + | log (datetime.datetime.now().strftime(" |
- | \\ | + | domoticzrequest(" |
- | while 1==1:\\ | + | else: |
- | currentstate = subprocess.call(' | + | log (datetime.datetime.now().strftime(" |
- | \\ | + | lastreported=1 |
- | if currentstate == 0 : lastsuccess=datetime.datetime.now()\\ | + | |
- | if currentstate == 0 and currentstate != previousstate and lastreported == 1 :\\ | + | if currentstate == 1 and currentstate != previousstate : |
- | log (datetime.datetime.now().strftime(" | + | log (datetime.datetime.now().strftime(" |
- | if currentstate == 0 and currentstate != previousstate and lastreported != 1 :\\ | + | |
- | if domoticzstatus() == 0 :\\ | + | if currentstate == 1 and (datetime.datetime.now()-lastsuccess).total_seconds()> |
- | log (datetime.datetime.now().strftime(" | + | if domoticzstatus() == 1 : |
- | domoticzrequest(" | + | log (datetime.datetime.now().strftime(" |
- | else:\\ | + | domoticzrequest(" |
- | log (datetime.datetime.now().strftime(" | + | else: |
- | lastreported=1\\ | + | log (datetime.datetime.now().strftime(" |
- | \\ | + | lastreported=0 |
- | if currentstate == 1 and currentstate != previousstate :\\ | + | |
- | log (datetime.datetime.now().strftime(" | + | time.sleep (float(interval)) |
- | \\ | + | |
- | if currentstate == 1 and (datetime.datetime.now()-lastsuccess).total_seconds() > float(cooldownperiod) and lastreported != 0 :\\ | + | previousstate=currentstate |
- | if domoticzstatus() == 1 :\\ | + | if check_for_instances.lower() == " |
- | log (datetime.datetime.now().strftime(" | + | </ |
- | domoticzrequest(" | + | |
- | else:\\ | + | |
- | log (datetime.datetime.now().strftime(" | + | |
- | lastreported=0\\ | + | |
- | \\ | + | |
- | time.sleep (float(interval))\\ | + | |
- | \\ | + | |
- | previousstate=currentstate\\ | + | |
- | if check_for_instances.lower() == " | + | |