Laget like gjerne en plugin til domoticz ut av det.
Opprett en ny mappen under domoticz-->plugins som heter eks badetassen
Dermed, lagre innholdet i koden som "plugin.py", og legg filen i mappen
Restart domoticz
"""
Altibox badetassen API
Author: deve87, 2023
Version: 1.0: Initial Version
"""
"""
<plugin key="Badetassen" name="Altibox badetassen API" author="deve87" version="1.0" wikilink="" externallink="https://prdl-apimgmt.lyse.no/apis/t/prod.altibox.lyse.no/temp/1.0/api/location">
<params>
<param field="Address" label="API URL" width="400px" required="true" default="https://prdl-apimgmt.lyse.no/apis/t/prod.altibox.lyse.no/temp/1.0/api/location"/>
<param field="Mode1" label="Authorization" width="400px" required="true" default="Bearer 9df43895-3d09-30d5-afe4-db2bf92a86f0"/>
<param field="Mode2" label="Place 1" width="400px" required="true" default="Osebakkenstranda"/>
<param field="Mode3" label="Place 2" width="400px" required="false" default=""/>
<param field="Mode4" label="Place 3" width="400px" required="false" default=""/>
<param field="Mode5" label="Update every x minutes" width="200px" required="true" default="60"/>
<param field="Mode6" label="Debug" width="75px">
<options>
<option label="False" value="Normal" default="False" />
<option label="True" value="Debug"/>
</options>
</param>
</params>
</plugin>
"""
import Domoticz
import requests
import time
from datetime import datetime, timedelta
class BasePlugin:
heartbeatsInterval = 10
heartbeatsCount = 0
def __init__(self):
self.debug = False
self.error = False
self.nextpoll = datetime.now()
self.pollinterval = 60
return
def onStart(self):
Domoticz.Debug("onStart called")
self.pollinterval = int(Parameters["Mode5"])*60
if Parameters["Mode6"] == 'Debug':
self.debug = True
Domoticz.Debugging(1)
DumpConfigToLog()
else:
Domoticz.Debugging(0)
if len(Parameters["Mode2"]) > 0:
if 1 not in Devices:
Domoticz.Device(Name=Parameters["Mode2"], Unit=1, TypeName="Temperature", Used=1).Create()
Domoticz.Log(Parameters["Mode2"]+" created")
if len(Parameters["Mode3"]) > 0:
if 2 not in Devices:
Domoticz.Device(Name=Parameters["Mode3"], Unit=2, TypeName="Temperature", Used=1).Create()
Domoticz.Log(Parameters["Mode3"]+" created")
if len(Parameters["Mode4"]) > 0:
if 3 not in Devices:
Domoticz.Device(Name=Parameters["Mode4"], Unit=3, TypeName="Temperature", Used=1).Create()
Domoticz.Log(Parameters["Mode4"]+" created")
self.checkAPI()
Domoticz.Heartbeat(self.heartbeatsInterval)
def onStop(self):
Domoticz.Log("Plugin is stopping.")
Domoticz.Debugging(0)
def onHeartbeat(self):
Domoticz.Debug("onHeartbeat called")
self.heartbeatsCount = self.heartbeatsCount + 1
if self.pollinterval <= self.heartbeatsInterval * self.heartbeatsCount:
self.heartbeatsCount = 0
self.checkAPI()
def checkAPI(self):
try:
url = Parameters["Address"]
headers = {
'accept': 'application/json',
'content-type': 'application/json',
'Authorization': Parameters["Mode1"]
}
response = requests.get(url, headers=headers)
jsondata = response.json()
lenght = len(jsondata)
for i in range(lenght):
if Parameters["Mode2"] in jsondata[i]["Name"]:
temp = jsondata[i]["lastTemperature"]
if 1 in Devices:
Devices[1].Update(nValue=1, sValue=temp)
if Parameters["Mode3"] in jsondata[i]["Name"]:
temp = jsondata[i]["lastTemperature"]
if 2 in Devices:
Devices[2].Update(nValue=1, sValue=temp)
if Parameters["Mode4"] in jsondata[i]["Name"]:
temp = jsondata[i]["lastTemperature"]
if 3 in Devices:
Devices[3].Update(nValue=1, sValue=temp)
except Exception as e:
Domoticz.Log("Error message: "+str(e))
global _plugin
_plugin = BasePlugin()
def onStart():
global _plugin
_plugin.onStart()
def onStop():
global _plugin
_plugin.onStop()
def onHeartbeat():
global _plugin
_plugin.onHeartbeat()
# Generic helper functions
def DumpConfigToLog():
for x in Parameters:
if Parameters[x] != "":
Domoticz.Debug( "'" + x + "':'" + str(Parameters[x]) + "'")
Domoticz.Debug("Device count: " + str(len(Devices)))
for x in Devices:
Domoticz.Debug("Device: " + str(x) + " - " + str(Devices[x]))
Domoticz.Debug("Device ID: '" + str(Devices[x].ID) + "'")
Domoticz.Debug("Device Name: '" + Devices[x].Name + "'")
Domoticz.Debug("Device nValue: " + str(Devices[x].nValue))
Domoticz.Debug("Device sValue: '" + Devices[x].sValue + "'")
return
Kun "Name" under "Product URL" linken vil fungere her.