Advertisement
Guest User

Untitled

a guest
May 11th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.33 KB | None | 0 0
  1. #!/usr/bin/python
  2. from lcd_display import lcd
  3. from time import sleep
  4. import RPi_I2C_driver
  5. from time import *
  6.  
  7. mylcd = RPi_I2C_driver.lcd()
  8. import subprocess
  9. import os
  10. import time
  11. import unicodedata
  12. import urllib, json
  13. import datetime
  14.  
  15. # Configuration
  16. cfgDomoticzHost = "192.168.0.116:8080"
  17. cfgSpeed = 3
  18. TotalScreens = 2
  19.  
  20. def get_domoticz_sensor(idx):
  21.         url = "http://"+str(cfgDomoticzHost)+"/json.htm?type=devices&rid="+str(idx)
  22.         response = urllib.urlopen(url);
  23.         data = json.loads(response.read())
  24.         if data["status"] == "OK":
  25.                 return data["result"][0]
  26.  
  27. def get_domoticz_info(result):
  28.     url = "http://"+str(cfgDomoticzHost)+"/json.htm?type=command&param=checkforupdate&forced=true"
  29.         response = urllib.urlopen(url);
  30.         data = json.loads(response.read())
  31.     if data["status"] == "OK":
  32.         return data[result]
  33.  
  34. ch = unichr(0xFF)
  35. deg = " C"
  36.  
  37. # Create screens
  38. def screen_home():
  39.     now = datetime.datetime.now()
  40.    
  41.     lcd.clear
  42.  
  43.     lcd.display_string(str(now.strftime("%d-%m-%Y")),1)
  44.     lcd.display_string(str(now.strftime("%H:%M")),2)
  45.  
  46.  
  47.     #i=0
  48.     #bar=''
  49.     #for i in range(0,20):
  50. #       bar=bar+unichr(255)
  51. #       lcd.display_string_l(bar,2)
  52. #       i += 1 
  53. #  
  54. #   geo = get_domoticz_sensor(65)["Status"]
  55. #   if geo == "On":
  56. #       status = "home"
  57. #   else:
  58. #       status = "away"
  59. #      
  60. #   lcd.display_string("Mike is " + status,3)
  61.    
  62. def screen_system():
  63.     lcd.clear
  64.     lcd.display_string_l("Akwarium   Pokoj", 1)
  65.     lcd.display_string_l(get_domoticz_sensor(1)["Data"] + "    " + get_domoticz_sensor(2)["Data"],2)
  66.     #lcd.display_string_l("Memory   : " + get_domoticz_sensor(1)["Data"],3)
  67.     #lcd.display_string_l("Temp     : " + get_domoticz_sensor(4)["Data"],4)
  68.  
  69. def screen_energy():
  70.     lcd.clear
  71.     lcd.display_string_l(" Na zewnatrz ", 1)
  72.     lcd.display_string_l("     " + get_domoticz_sensor(11)["Data"],2)
  73.     #lcd.display_string_l("Today  : " + get_domoticz_sensor(9)["CounterToday"],3)
  74.     #lcd.display_string_l("" ,4)
  75.  
  76. def screen_weather():
  77.     lcd.clear
  78.     lcd.display_string_l(unichr(255)+" Weather "+(ch*10), 1)
  79.     lcd.display_string_l("Temp    : " + str(get_domoticz_sensor(1)["Temp"]) + deg,2)
  80.     lcd.display_string_l("Humid   : " + str(get_domoticz_sensor(119)["Humidity"]) + " %", 3)
  81.     lcd.display_string_l("Baro    : " + str(get_domoticz_sensor(119)["Barometer"]) + " mb",4)
  82.  
  83. def screen_temps():
  84.     lcd.clear
  85.     lcd.display_string_l(unichr(255)+" Temps "+(ch*12), 1)
  86.     lcd.display_string_l("Lounge   : " + str(get_domoticz_sensor(53)["Temp"]) + deg,2)
  87.     lcd.display_string_l("Hive     : " + str(get_domoticz_sensor(30)["Temp"]) + deg,3)
  88.     lcd.display_string_l("Target   : " + str(get_domoticz_sensor(31)["Temp"]) + deg,4)
  89.  
  90. def screen_lights():
  91.     lcd.clear
  92.     lcd.display_string_l(unichr(255)+" Lights "+(ch*11), 1)
  93.     lcd.display_string_l("Inside   : " + str(get_domoticz_sensor(15)["Status"]),2)
  94.     lcd.display_string_l("Outside  : " + str(get_domoticz_sensor(13)["Status"]),3)
  95.     lcd.display_string_l("",4)
  96.  
  97. # Determine order of the screens
  98. screens = {    
  99.         0 : screen_home,
  100.         1 : screen_system,
  101.         2 : screen_energy,
  102.         3 : screen_weather,
  103.         4 : screen_temps,
  104.         5 : screen_lights,
  105.           }
  106.  
  107. # Start LCD
  108. lcd = lcd()
  109. # Display screens
  110. i=0
  111. while 1:
  112.     try:
  113.         screens[i]()
  114.     except:
  115.         pass
  116.  
  117.     sleep(cfgSpeed)
  118.     i += 1
  119.     if i == TotalScreens+1:
  120.         i=0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement