Created
May 16, 2019 18:59
-
-
Save shevabam/ecf6d4a06538c89f667620046a95fd2a to your computer and use it in GitHub Desktop.
Pushbullet sensor temperature notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
#pip install git+https://github.com/Azelphur/pyPushBullet.git | |
from pushbullet.pushbullet import PushBullet | |
import json, os | |
# Sensor ID (/sys/bus/w1/devices/{SENSOR_ID}/w1_slave) | |
SENSOR_ID = "xxx" | |
# Maximum allowed temperature in greenhouse | |
MAX_TEMP_ALLOWED = 45 | |
# Pushbullet API Key | |
PB_API_KEY = "xxx" | |
# Send Pushbullet notification to all devices pushable | |
def sendNotification(): | |
pb = PushBullet(PB_API_KEY) | |
# Get a list of devices | |
devices = pb.getDevices() | |
#print(json.dumps(devices, indent=4)) | |
title = "Pipo : température élevée !" | |
text = "La température est de "+str(temp)+"°C dans la serre !" | |
for device in devices: | |
if device['pushable']: | |
note = pb.pushNote(device["iden"], title, text) | |
# Retrieve temperature value | |
def getTemperature(): | |
sensor_file = "/sys/bus/w1/devices/"+SENSOR_ID+"/w1_slave" | |
temp_c = 0 | |
if os.path.isfile(sensor_file): | |
f = open(sensor_file, 'r') | |
lines = f.readlines() | |
f.close() | |
if lines[0].strip()[-3:] == 'YES': | |
equals_pos = lines[1].find('t=') | |
if equals_pos != -1: | |
temp_string = lines[1][equals_pos+2:] | |
temp_c = float(temp_string) / 1000.0 | |
temp = round(temp_c, 1) | |
return temp | |
# ####### | |
temp = getTemperature() | |
if temp > MAX_TEMP_ALLOWED: | |
sendNotification() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment