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:41] madkodomotique [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 sur Raspberry PI 2 ou 3 ======
  
 +Avec l'installation via Docker.
 +
 +<code>
 +pacman -S docker
 +</code>
  
-Configuration de tellstick duo pour piloter une prise DIO:+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+ ======
 +
 +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 /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\
  
-*/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 */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
 +#   Title: check_device_online.py
 +#   Author: Chopper_Rob
 +#   Date: 25-02-2015
 +#   Info: Checks the presence of the given device on the network and reports back to domoticz
 +#   URL : https://www.chopperrob.nl/domoticz/5-report-devices-online-status-to-domoticz
 +#   Version : 1.6.2
  
-#!/usr/bin/python\\  +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://www.chopperrob.nl/domoticz/5-report-devices-online-status-to-domoticz\\  +import urllib2 
-#  Version : 1.6.2\\  +import json 
-\\  +import base64 
-import sys\\  + 
-import datetime\\  +# Settings for the domoticz server 
-import time\\  +domoticzserver="hdmipi:8080" 
-import os\\  +domoticzusername = "admin" 
-import subprocess\\  +domoticzpassword = "admin" 
-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. 
-\\  +#log_to_file = False 
-# Settings for the domoticz server\\  +log_to_file = True 
-domoticzserver="hdmipi:8080"\\  + 
-domoticzusername = "admin"\\  +# The script supports two types to check if another instance of the script is running. 
-domoticzpassword = "admin"\\  +# 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't exist or it is older then 3 * Interval it will keep running, otherwise is stops. 
-#log_to_file = False\\  +# Please chose the option you want to use "ps" or "pid", if this option is kept empty it will not check and just run. 
-log_to_file = True\\  +check_for_instances = "pid" 
-\\  + 
-# 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't exist or it is older then 3 * Interval it will keep running, otherwise is stops.\\  + 
-# Please chose the option you want to use "ps" or "pid", if this option is kept empty it will not check and just run.\\  +device=sys.argv[1] 
-check_for_instances = "pid"\\  +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.")\\  +#base64string = base64.encodestring('%s:%s' % (domoticzusername, domoticzpassword)).replace('\n', ''
-sys.exit(0)\\  +domoticzurl = 'http://'+domoticzserver+'/json.htm?type=devices&filter=all&used=true&order=Name' 
-\\  + 
-device=sys.argv[1]\\  +if check_for_instances.lower() == "pid": 
-switchid=sys.argv[2]\\  +  pidfile = sys.argv[0] + '_' + sys.argv[1] + '.pid' 
-interval=sys.argv[3]\\  +  if os.path.isfile( pidfile ): 
-cooldownperiod=sys.argv[4]\\  +    print datetime.datetime.now().strftime("%H:%M:%S") + "- pid file exists" 
-previousstate=-1\\  +    if (time.time() - os.path.getmtime(pidfile)) <(float(interval) * 3): 
-lastsuccess=datetime.datetime.now()\\  +      print datetime.datetime.now().strftime("%H:%M:%S") + "- script seems to be still running, exiting" 
-lastreported=-1\\  +      print datetime.datetime.now().strftime("%H:%M:%S") + "- If this is not correct, please delete file " + pidfile 
-#base64string = base64.encodestring('%s:%s' % (domoticzusername, domoticzpassword)).replace('%%\%%n', '')\\  +      sys.exit(0) 
-domoticzurl = 'http://'+domoticzserver+'/json.htm?type=devices&filter=all&used=true&order=Name'\\  +    else: 
-\\  +      print datetime.datetime.now().strftime("%H:%M:%S") + "- Seems to be an old file, ignoring." 
-if check_for_instances.lower() == "pid":\\  +  else: 
-pidfile = sys.argv[0] + '_' + sys.argv[1] + '.pid'\\  +    open(pidfile, 'w').close() 
-if os.path.isfile( pidfile ):\\  + 
-print datetime.datetime.now().strftime("%H:%M:%S") + "- pid file exists"\\  +if check_for_instances.lower() == "ps": 
-if (time.time() - os.path.getmtime(pidfile)) < (float(interval) * 3):\\  +  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 seems to be still running, exiting"\\  +    print (datetime.datetime.now().strftime("%H:%M:%S") + "- script already running. exiting."
-print datetime.datetime.now().strftime("%H:%M:%S") + "- If this is not correct, please delete file " + pidfile\\  +    sys.exit(0) 
-sys.exit(0)\\  + 
-else:\\  +def log(message): 
-print datetime.datetime.now().strftime("%H:%M:%S") + "- Seems to be an old file, ignoring."\\  +  print message 
-else:\\  +  if log_to_file == True: 
-open(pidfile, 'w').close()\\  +    logfile = open(sys.argv[0] + '_' + sys.argv[1] + '.log', "a"
-\\  +    logfile.write(message + "\n"
-if check_for_instances.lower() == "ps":\\  +    logfile.close() 
-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.")\\  +def domoticzstatus (): 
-sys.exit(0)\\  +  json_object = json.loads(domoticzrequest(domoticzurl)) 
-\\  +  status = 0 
-def log(message):\\  +  switchfound = False 
-print message\\  +  if json_object["status"] == "OK": 
-if log_to_file == True:\\  +    for i, v in enumerate(json_object["result"]): 
-logfile = open(sys.argv[0] + '_' + sys.argv[1] + '.log', "a")\\  +      if json_object["result"][i]["idx"] == switchid and "Lighting" in json_object["result"][i]["Type"] : 
-logfile.write(message + "%%\%%n")\\  +        switchfound = True 
-logfile.close()\\  +        if json_object["result"][i]["Status"] == "On": 
-\\  +          status = 1 
-def domoticzstatus ():\\  +        if json_object["result"][i]["Status"] == "Off": 
-json_object = json.loads(domoticzrequest(domoticzurl))\\  +          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."
-switchfound = False\\  +  return status 
-if json_object["status"] == "OK":\\  + 
-for i, v in enumerate(json_object["result"]):\\  +def domoticzrequest (url): 
-if json_object["result"][i]["idx"] == switchid and "Lighting" in json_object["result"][i]["Type"] :\\  +  request = urllib2.Request(url) 
-switchfound = True\\  +  #request.add_header("Authorization", "Basic %s" % base64string) 
-if json_object["result"][i]["Status"] == "On":\\  +  try: 
-status = 1\\  +    response = urllib2.urlopen(request) 
-if json_object["result"][i]["Status"] == "Off":\\  +  except: 
-status = 0\\  +    print("error opening %s" % url) 
-if switchfound == False: print (datetime.datetime.now().strftime("%H:%M:%S") + "- Error. Could not find switch idx in Domoticz response. Defaulting to switch off.")\\  +    sys.exit(-1) 
-return status\\  +  else: 
-\\  +    return response.read() 
-def domoticzrequest (url):\\  + 
-request = urllib2.Request(url)\\  +log (datetime.datetime.now().strftime("%H:%M:%S") + "- script started."
-#request.add_header("Authorization", "Basic %s" % base64string)\\  + 
-try:\\  +lastreported = domoticzstatus() 
-response = urllib2.urlopen(request)\\  +if lastreported == 1 : 
-except:\\  +  log (datetime.datetime.now().strftime("%H:%M:%S") + "- according to domoticz, " + device + " is online"
-print("error opening %s" % url)\\  +if lastreported == 0 : 
-sys.exit(-1)\\  +  log (datetime.datetime.now().strftime("%H:%M:%S") + "- according to domoticz, " + device + " is offline"
-else:\\  + 
-return response.read()\\  +while 1==1: 
-\\  +  currentstate = subprocess.call('ping -q -c1 -W 1 '+ device + '> /dev/null', shell=True) 
-log (datetime.datetime.now().strftime("%H:%M:%S") + "- script started.")\\  + 
-\\  +  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("%H:%M:%S") + "- " + device + " online, no need to tell domoticz"
-log (datetime.datetime.now().strftime("%H:%M:%S") + "- according to domoticz, " + device + " is online")\\  +  if currentstate == 0 and currentstate != previousstate and lastreported != 1 : 
-if lastreported == 0 :\\  +    if domoticzstatus() == 0 : 
-log (datetime.datetime.now().strftime("%H:%M:%S") + "- according to domoticz, " + device + " is offline")\\  +      log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " online, tell domoticz it's back"
-\\  +      domoticzrequest("http://" + domoticzserver + "/json.htm?type=command¶m=switchlight&idx=" + switchid + "&switchcmd=On&level=0"
-while 1==1:\\  +    else: 
-currentstate = subprocess.call('ping -q -c1 -W 1 '+ device + ' > /dev/null', shell=True)\\  +      log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " online, but domoticz already knew"
-\\  +    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("%H:%M:%S") + "- " + device + " online, no need to tell domoticz")\\  +    log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " offline, waiting for it to come back"
-if currentstate == 0 and currentstate != previousstate and lastreported != 1 :\\  + 
-if domoticzstatus() == 0 :\\  +  if currentstate == 1 and (datetime.datetime.now()-lastsuccess).total_seconds()> float(cooldownperiod) and lastreported != 0 : 
-log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " online, tell domoticz it's back")\\  +    if domoticzstatus() == 1 : 
-domoticzrequest("http://" + domoticzserver + "/json.htm?type=command&param=switchlight&idx=" + switchid + "&switchcmd=On&level=0")\\  +      log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " offline, tell domoticz it's gone"
-else:\\  +      domoticzrequest("http://" + domoticzserver + "/json.htm?type=command¶m=switchlight&idx=" + switchid + "&switchcmd=Off&level=0"
-log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " online, but domoticz already knew")\\  +    else: 
-lastreported=1\\  +      log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " offline, but domoticz already knew"
-\\  +    lastreported=0 
-if currentstate == 1 and currentstate != previousstate :\\  + 
-log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " offline, waiting for it to come back")\\  +  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() == "pid": open(pidfile, 'w').close() 
-log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " offline, tell domoticz it's gone")\\  +</code>
-domoticzrequest("http://" + domoticzserver + "/json.htm?type=command&param=switchlight&idx=" + switchid + "&switchcmd=Off&level=0")\\  +
-else:\\  +
-log (datetime.datetime.now().strftime("%H:%M:%S") + "- " + device + " offline, but domoticz already knew")\\  +
-lastreported=0\\  +
-\\  +
-time.sleep (float(interval))\\  +
-\\  +
-previousstate=currentstate\\  +
-if check_for_instances.lower() == "pid": open(pidfile, 'w').close()+
  
  • domotique.1433691709.txt.gz
  • Dernière modification : 2015/06/07 15:41
  • de madko