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:45] – madko | domotique [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' | ||
+ | |||
+ | < | ||
+ | pacman -S docker | ||
+ | </ | ||
+ | |||
+ | 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+ ====== | ====== 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 / |
< | < | ||
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 * * * * / | ||
+ | </ | ||
Et le script check_device_online.py: | Et le script check_device_online.py: | ||
- | < | + | < |
+ | # | ||
# | # | ||
# | # | ||
Ligne 51: | Ligne 87: | ||
# URL : https:// | # URL : https:// | ||
# | # | ||
- | + | ||
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=" | domoticzserver=" | ||
domoticzusername = " | domoticzusername = " | ||
domoticzpassword = " | domoticzpassword = " | ||
- | + | ||
# 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 = 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 " | # Please chose the option you want to use " | ||
check_for_instances = " | check_for_instances = " | ||
- | + | ||
- | + | ||
- | + | ||
# 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: | ||
# | # | ||
domoticzurl = ' | domoticzurl = ' | ||
- | + | ||
if check_for_instances.lower() == " | if check_for_instances.lower() == " | ||
pidfile = sys.argv[0] + ' | pidfile = sys.argv[0] + ' | ||
if os.path.isfile( pidfile ): | if os.path.isfile( pidfile ): | ||
print datetime.datetime.now().strftime(" | print datetime.datetime.now().strftime(" | ||
- | if (time.time() - os.path.getmtime(pidfile)) < (float(interval) * 3): | + | if (time.time() - os.path.getmtime(pidfile)) < |
print datetime.datetime.now().strftime(" | print datetime.datetime.now().strftime(" | ||
print datetime.datetime.now().strftime(" | print datetime.datetime.now().strftime(" | ||
Ligne 107: | Ligne 141: | ||
print datetime.datetime.now().strftime(" | print datetime.datetime.now().strftime(" | ||
else: | else: | ||
- | open(pidfile, | + | open(pidfile, |
- | + | ||
if check_for_instances.lower() == " | if check_for_instances.lower() == " | ||
- | if int(subprocess.check_output(' | + | if int(subprocess.check_output(' |
print (datetime.datetime.now().strftime(" | print (datetime.datetime.now().strftime(" | ||
sys.exit(0) | sys.exit(0) | ||
- | + | ||
def log(message): | def log(message): | ||
print message | print message | ||
Ligne 120: | Ligne 154: | ||
logfile.write(message + " | logfile.write(message + " | ||
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[" | if json_object[" | ||
switchfound = True | switchfound = True | ||
- | if json_object[" | + | if json_object[" |
status = 1 | status = 1 | ||
- | if json_object[" | + | if json_object[" |
status = 0 | status = 0 | ||
if switchfound == False: print (datetime.datetime.now().strftime(" | if switchfound == False: print (datetime.datetime.now().strftime(" | ||
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(" | log (datetime.datetime.now().strftime(" | ||
- | + | ||
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(" | log (datetime.datetime.now().strftime(" | ||
- | + | ||
while 1==1: | while 1==1: | ||
- | currentstate = subprocess.call(' | + | currentstate = subprocess.call(' |
- | + | ||
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(" | log (datetime.datetime.now().strftime(" | ||
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(" | log (datetime.datetime.now().strftime(" | ||
- | domoticzrequest(" | + | domoticzrequest(" |
else: | else: | ||
log (datetime.datetime.now().strftime(" | log (datetime.datetime.now().strftime(" | ||
lastreported=1 | lastreported=1 | ||
- | + | ||
if currentstate == 1 and currentstate != previousstate : | if currentstate == 1 and currentstate != previousstate : | ||
log (datetime.datetime.now().strftime(" | log (datetime.datetime.now().strftime(" | ||
- | + | ||
- | 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()> |
if domoticzstatus() == 1 : | if domoticzstatus() == 1 : | ||
log (datetime.datetime.now().strftime(" | log (datetime.datetime.now().strftime(" | ||
- | domoticzrequest(" | + | domoticzrequest(" |
else: | else: | ||
log (datetime.datetime.now().strftime(" | log (datetime.datetime.now().strftime(" | ||
lastreported=0 | lastreported=0 | ||
- | + | ||
time.sleep (float(interval)) | time.sleep (float(interval)) | ||
- | + | ||
previousstate=currentstate | previousstate=currentstate | ||
- | if check_for_instances.lower() == " | + | if check_for_instances.lower() == " |
+ | </ |