add readHomaticIP.py and readBresserTempSensor.py

This commit is contained in:
robert 2021-02-01 06:59:33 +01:00
parent 890b7df0eb
commit 710eaa90e6
2 changed files with 145 additions and 0 deletions

60
readBresserTempSensor.py Executable file
View File

@ -0,0 +1,60 @@
import json
import sys
import os
# Import MQTT client.
import paho.mqtt.publish as publish
import paho.mqtt.client as paho
# MQTT credentials
#mqtt_username = 'homeassistant' # MQTT client username
#mqtt_password = '3355' # MQTT client password
#client_id = 'temperature' # unique client_id
mqtt_broker = "raspberrypi" # broker address, usually your HASS IP address
# create the MQTT client
client = paho.Client(protocol=paho.MQTTv31) # * set a random string (max 23 chars)
# Command topic
#topic = 'weathersensors/garden'
# client connection
#client.username_pw_set(mqtt_username, mqtt_password) # MQTT server credentials
client.connect(mqtt_broker, 1883, 60) # MQTT server address
#client.loop_start()
process = os.popen('/usr/local/bin/rtl_433 -R 42 -R 03 -F json -T 65 -M time:utc:usec')
processData = process.read().split('\n')
print("processData: ")
print(processData)
for i in processData:
print("i: ")
print(len(i))
print(i)
if len(i) > 0:
jsonData = (json.loads(i))
model = str(jsonData['model'])
if model == "Hideki-TS04":
topic = 'weathersensors/garden'
else:
topic = 'weathersensors/pool'
time = str(jsonData['time'])
battery = str(jsonData['battery_ok'])
temperature = str(jsonData['temperature_C'])
humidity = str(jsonData['humidity'])
client.publish(topic + "/time", "" + time)
client.publish(topic + "/battery", "" + battery)
client.publish(topic + "/temperature", "" + temperature)
client.publish(topic + "/humidity", "" + humidity)
process.close()

85
readHomematicIP.py Executable file
View File

@ -0,0 +1,85 @@
import json
import sys
import os
# Homematic IP
import homematicip
from homematicip.home import Home
from homematicip.device import ShutterContact,HeatingThermostat,PlugableSwitchMeasuring,WallMountedThermostatPro
# Import MQTT client.
import paho.mqtt.publish as publish
import paho.mqtt.client as paho
# MQTT credentials
# mqtt_username = 'homeassistant' # MQTT client username
# mqtt_password = '3355' # MQTT client password
# client_id = 'temperature' # unique client_id
mqtt_broker = "raspberrypi" # broker address, usually your HASS IP address
# create the MQTT client
global client
client = paho.Client(protocol=paho.MQTTv31) # * set a random string (max 23 chars)
# client connection
# client.username_pw_set(mqtt_username, mqtt_password) # MQTT server credentials
client.connect(mqtt_broker, 1883, 60) # MQTT server address
# Homematic IP
config = homematicip.find_and_load_config_file()
home = Home()
home.set_auth_token(config.auth_token)
home.init(config.access_point)
def write_shutter(room,device):
print(room, " ", device.label, " ", device.lastStatusUpdate, " ", device.windowState)
#print(device)
def write_plugableswitchmeasuring(room,device):
print(room, " ", device.label, " ", device.lastStatusUpdate, " ", device.currentPowerConsumption, " ", device.energyCounter)
def write_heatingthermostat(room,device):
print(room, " ", device.label, " ", device.lastStatusUpdate)
def write_wallmountedthermostatpro(room,device):
global time
global deviceName
global actualTemperature
global setPointTemperature
global humidity
time = device.lastStatusUpdate
deviceName = device.label
actualTemperature = device.actualTemperature
setPointTemperature = device.setPointTemperature
humidity = device.humidity
topic = 'weathersensors/'+room
#print(topic)
client.publish(topic + "/time", "" + str(time))
client.publish(topic + "/actualTemperature", "" + str(actualTemperature))
client.publish(topic + "/setPointTemperature", "" + str(setPointTemperature))
client.publish(topic + "/humidity", "" + str(humidity))
print({"Room":room, "Device Name":device.label, "Last Status Update" : device.lastStatusUpdate, "Actual Temperature":device.actualTemperature, "Set Point Temperature":device.setPointTemperature,"Humidity":device.humidity})
def main():
global home
home.get_current_state()
for group in home.groups:
if group.groupType=="META":
for device in group.devices:
if isinstance(device,ShutterContact):
write_shutter(group.label,device)
elif isinstance(device,HeatingThermostat):
write_heatingthermostat(group.label,device)
elif isinstance(device,PlugableSwitchMeasuring):
write_plugableswitchmeasuring(group.label,device)
elif isinstance(device,WallMountedThermostatPro):
write_wallmountedthermostatpro(group.label,device)
if __name__ == "__main__":
main()