Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

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:45] madkodomotique [2016/03/21 17:21] (Version actuelle) – [Jeedom sur Raspberry PI 2 ou 3] madko
Ligne 1: Ligne 1:
 +====== Jeedom sur Raspberry PI 2 ou 3 ======
 +
 +Avec l'installation via Docker.
 +
 +<code>
 +pacman -S docker
 +</code>
 +
 +Mettre son utilisateur courant dans le groupe docker (pour éviter sudo).
 +
 +Utilisation de l'image suivante [[https://hub.docker.com/r/sbeuzit/rpi-jeedom/|https://hub.docker.com/r/sbeuzit/rpi-jeedom/]] avec les commandes qui suivent:
 +
 +<code>
 +docker pull sbeuzit/rpi-jeedom-data
 +docker run --name data sbeuzit/rpi-jeedom-data
 +</code>
 +
 +Cette image ne sert que pour conserver les données. Il faut ensuite un containeur pour la partie MySQL :
 +
 +<code>
 +docker pull hypriot/rpi-mysql
 +docker run --name jeedom-mysql -e MYSQL_ROOT_PASSWORD=my_mysql_password --volumes-from data -d hypriot/rpi-mysql
 +</code>
 +
 +Il s'agit de l'image fournit pas hypriot, donc idéale pour Raspberry PI. A noter qu'il faut plus de 512Mo de RAM, donc il faut un minimum un RPI 2 ou supérieur.
 +
 +Il ne reste plus qu'à lancer le containeur jeedom avec le lien vers nos containeurs précédents :
 +
 +<code>
 +docker run -d --link jeedom-mysql:mysql --device=/dev/ttyUSB0:/dev/ttyUSB0 --name jeedom -p 80:80 -p 8083:8083 -p 443:443
 +</code>
 +
 +A noter le /dev/ttyACM0 pour donner accès à votre clef ZWAVE.
 +
 ====== Domoticz sur Raspberry PI B+ ====== ====== Domoticz sur Raspberry PI B+ ======
  
 Récuperer les sources et les compiler (pas trop lourd même sur un RPI). Récuperer les sources et les compiler (pas trop lourd même sur un RPI).
  
-Configuration de tellstick duo pour piloter une prise DIO:+Configuration de tellstick duo pour piloter une prise DIO fichier /etc/tellstick.conf :
  
 <code> <code>
Ligne 34: Ligne 68:
 } }
 </code> </code>
- 
  
 Quelques tâches en cron pour les tests sur IP: Quelques tâches en cron pour les tests sur IP:
  
-<code>*/10 * * * *  /home/pi/domoticz/scripts/check_device_online.py 192.168.2.5 6 60 120\\  +<code> 
-*/10 * * * *  /home/pi/domoticz/scripts/check_device_online.py 192.168.2.3 7 60 120</code>+*/10 * * * *  /home/pi/domoticz/scripts/check_device_online.py 192.168.2.5 6 60 120\
  
 +*/10 * * * *  /home/pi/domoticz/scripts/check_device_online.py 192.168.2.3 7 60 120
 +</code>
  
 Et le script check_device_online.py: Et le script check_device_online.py:
  
-<code>#!/usr/bin/python+<code> 
 +#!/usr/bin/python
 #   Title: check_device_online.py #   Title: check_device_online.py
 #   Author: Chopper_Rob #   Author: Chopper_Rob
Ligne 51: Ligne 87:
 #   URL : https://www.chopperrob.nl/domoticz/5-report-devices-online-status-to-domoticz #   URL : https://www.chopperrob.nl/domoticz/5-report-devices-online-status-to-domoticz
 #   Version : 1.6.2 #   Version : 1.6.2
- +
 import sys import sys
 import datetime import datetime
Ligne 60: Ligne 96:
 import json import json
 import base64 import base64
- +
 # Settings for the domoticz server # Settings for the domoticz server
 domoticzserver="hdmipi:8080" domoticzserver="hdmipi:8080"
 domoticzusername = "admin" domoticzusername = "admin"
 domoticzpassword = "admin" domoticzpassword = "admin"
- +
 # If enabled. The script will log to the file _.log # If enabled. The script will log to the file _.log
 # Logging to file only happens after the check for other instances, before that it only prints to screen. # Logging to file only happens after the check for other instances, before that it only prints to screen.
 #log_to_file = False #log_to_file = False
 log_to_file = True log_to_file = True
- +
 # The script supports two types to check if another instance of the script is running. # The script supports two types to check if another instance of the script is running.
 # One will use the ps command, but this does not work on all machine (Synology has problems) # One will use the ps command, but this does not work on all machine (Synology has problems)
Ligne 78: Ligne 114:
 # Please chose the option you want to use "ps" or "pid", if this option is kept empty it will not check and just run. # Please chose the option you want to use "ps" or "pid", if this option is kept empty it will not check and just run.
 check_for_instances = "pid" check_for_instances = "pid"
-  +
-  +
- +
 # DO NOT CHANGE BEYOND THIS LINE # DO NOT CHANGE BEYOND THIS LINE
 if len(sys.argv) != 5 : if len(sys.argv) != 5 :
   print ("Not enough parameters. Needs %Host %Switchid %Interval %Cooldownperiod.")   print ("Not enough parameters. Needs %Host %Switchid %Interval %Cooldownperiod.")
   sys.exit(0)   sys.exit(0)
- +
 device=sys.argv[1] device=sys.argv[1]
 switchid=sys.argv[2] switchid=sys.argv[2]
Ligne 95: Ligne 129:
 #base64string = base64.encodestring('%s:%s' % (domoticzusername, domoticzpassword)).replace('\n', '') #base64string = base64.encodestring('%s:%s' % (domoticzusername, domoticzpassword)).replace('\n', '')
 domoticzurl = 'http://'+domoticzserver+'/json.htm?type=devices&filter=all&used=true&order=Name' domoticzurl = 'http://'+domoticzserver+'/json.htm?type=devices&filter=all&used=true&order=Name'
- +
 if check_for_instances.lower() == "pid": if check_for_instances.lower() == "pid":
   pidfile = sys.argv[0] + '_' + sys.argv[1] + '.pid'   pidfile = sys.argv[0] + '_' + sys.argv[1] + '.pid'
   if os.path.isfile( pidfile ):   if os.path.isfile( pidfile ):
     print datetime.datetime.now().strftime("%H:%M:%S") + "- pid file exists"     print datetime.datetime.now().strftime("%H:%M:%S") + "- pid file exists"
-    if (time.time() - os.path.getmtime(pidfile)) < (float(interval) * 3):+    if (time.time() - os.path.getmtime(pidfile)) <(float(interval) * 3):
       print datetime.datetime.now().strftime("%H:%M:%S") + "- script seems to be still running, exiting"       print datetime.datetime.now().strftime("%H:%M:%S") + "- script seems to be still running, exiting"
       print datetime.datetime.now().strftime("%H:%M:%S") + "- If this is not correct, please delete file " + pidfile       print datetime.datetime.now().strftime("%H:%M:%S") + "- If this is not correct, please delete file " + pidfile
Ligne 107: Ligne 141:
       print datetime.datetime.now().strftime("%H:%M:%S") + "- Seems to be an old file, ignoring."       print datetime.datetime.now().strftime("%H:%M:%S") + "- Seems to be an old file, ignoring."
   else:   else:
-    open(pidfile, 'w').close()  +    open(pidfile, 'w').close() 
- +
 if check_for_instances.lower() == "ps": if check_for_instances.lower() == "ps":
-  if int(subprocess.check_output('ps x | grep \'' + sys.argv[0] + ' ' + sys.argv[1] + '\' | grep -cv grep', shell=True)) > 2 :+  if int(subprocess.check_output('ps x | grep \'' + sys.argv[0] + ' ' + sys.argv[1] + '\' | grep -cv grep', shell=True))> 2 :
     print (datetime.datetime.now().strftime("%H:%M:%S") + "- script already running. exiting.")     print (datetime.datetime.now().strftime("%H:%M:%S") + "- script already running. exiting.")
     sys.exit(0)     sys.exit(0)
- +
 def log(message): def log(message):
   print message   print message
Ligne 120: Ligne 154:
     logfile.write(message + "\n")     logfile.write(message + "\n")
     logfile.close()     logfile.close()
- +
 def domoticzstatus (): def domoticzstatus ():
   json_object = json.loads(domoticzrequest(domoticzurl))   json_object = json.loads(domoticzrequest(domoticzurl))
Ligne 129: Ligne 163:
       if json_object["result"][i]["idx"] == switchid and "Lighting" in json_object["result"][i]["Type"] :       if json_object["result"][i]["idx"] == switchid and "Lighting" in json_object["result"][i]["Type"] :
         switchfound = True         switchfound = True
-        if json_object["result"][i]["Status"] == "On": +        if json_object["result"][i]["Status"] == "On":
           status = 1           status = 1
-        if json_object["result"][i]["Status"] == "Off": +        if json_object["result"][i]["Status"] == "Off":
           status = 0           status = 0
   if switchfound == False: print (datetime.datetime.now().strftime("%H:%M:%S") + "- Error. Could not find switch idx in Domoticz response. Defaulting to switch off.")   if switchfound == False: print (datetime.datetime.now().strftime("%H:%M:%S") + "- Error. Could not find switch idx in Domoticz response. Defaulting to switch off.")
   return status   return status
- +
 def domoticzrequest (url): def domoticzrequest (url):
   request = urllib2.Request(url)   request = urllib2.Request(url)
Ligne 146: Ligne 180:
   else:   else:
     return response.read()     return response.read()
- +
 log (datetime.datetime.now().strftime("%H:%M:%S") + "- script started.") log (datetime.datetime.now().strftime("%H:%M:%S") + "- script started.")
- +
 lastreported = domoticzstatus() lastreported = domoticzstatus()
 if lastreported == 1 : if lastreported == 1 :
Ligne 154: Ligne 188:
 if lastreported == 0 : if lastreported == 0 :
   log (datetime.datetime.now().strftime("%H:%M:%S") + "- according to domoticz, " + device + " is offline")   log (datetime.datetime.now().strftime("%H:%M:%S") + "- according to domoticz, " + device + " is offline")
- +
 while 1==1: while 1==1:
-  currentstate = subprocess.call('ping -q -c1 -W 1 '+ device + ' > /dev/null', shell=True) +  currentstate = subprocess.call('ping -q -c1 -W 1 '+ device + '> /dev/null', shell=True) 
- +
   if currentstate == 0 : lastsuccess=datetime.datetime.now()   if currentstate == 0 : lastsuccess=datetime.datetime.now()
-  if currentstate == 0 and currentstate != previousstate and lastreported == 1 : +  if currentstate == 0 and currentstate != previousstate and lastreported == 1 :
     log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " online, no need to tell domoticz")     log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " online, no need to tell domoticz")
   if currentstate == 0 and currentstate != previousstate and lastreported != 1 :   if currentstate == 0 and currentstate != previousstate and lastreported != 1 :
     if domoticzstatus() == 0 :     if domoticzstatus() == 0 :
       log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " online, tell domoticz it's back")       log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " online, tell domoticz it's back")
-      domoticzrequest("http://" + domoticzserver + "/json.htm?type=command&param=switchlight&idx=" + switchid + "&switchcmd=On&level=0")+      domoticzrequest("http://" + domoticzserver + "/json.htm?type=command¶m=switchlight&idx=" + switchid + "&switchcmd=On&level=0")
     else:     else:
       log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " online, but domoticz already knew")       log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " online, but domoticz already knew")
     lastreported=1     lastreported=1
- +
   if currentstate == 1 and currentstate != previousstate :   if currentstate == 1 and currentstate != previousstate :
     log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " offline, waiting for it to come back")     log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " offline, waiting for it to come back")
-  + 
-  if currentstate == 1 and (datetime.datetime.now()-lastsuccess).total_seconds() > float(cooldownperiod) and lastreported != 0 :+  if currentstate == 1 and (datetime.datetime.now()-lastsuccess).total_seconds()> float(cooldownperiod) and lastreported != 0 :
     if domoticzstatus() == 1 :     if domoticzstatus() == 1 :
       log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " offline, tell domoticz it's gone")       log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " offline, tell domoticz it's gone")
-      domoticzrequest("http://" + domoticzserver + "/json.htm?type=command&param=switchlight&idx=" + switchid + "&switchcmd=Off&level=0")+      domoticzrequest("http://" + domoticzserver + "/json.htm?type=command¶m=switchlight&idx=" + switchid + "&switchcmd=Off&level=0")
     else:     else:
       log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " offline, but domoticz already knew")       log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " offline, but domoticz already knew")
     lastreported=0     lastreported=0
- +
   time.sleep (float(interval))   time.sleep (float(interval))
- +
   previousstate=currentstate   previousstate=currentstate
-  if check_for_instances.lower() == "pid": open(pidfile, 'w').close()</code>+  if check_for_instances.lower() == "pid": open(pidfile, 'w').close() 
 +</code> 
  • domotique.1433691936.txt.gz
  • Dernière modification : 2015/06/07 15:45
  • de madko