I found a method to delete sensor data via the json interface but is this alo possible via the plugin? As this would be more direct? If not, what is the best way to access the json api from the plugin? As I don't want to configure the local IP Adress?
The reason to do this is that I'm building a plugin to read solar forecasts. I update them for the next 3 days every half hour (approx., config) but it seems that the database gets a new datapoit each time I update the sensor with future values and then I'm not really sue wha tthe latest forecasts are. So my idea is to delete old values prior to adding new.
Creating device like this:
Code: Select all
if self.deviceId not in Devices or (1 not in Devices[self.deviceId].Units):
Domoticz.Unit(Name=self.deviceId + ' - 24h forecast', Unit=1, Type=243, Subtype=33, Switchtype=4, Used=1, DeviceID=self.deviceId).Create()
Code: Select all
sValue = str(json["result"]["watts"][dtline])+";"+str(json["result"]["watt_hours_period"][dtline])+";"+str(dtline)
self.UpdateDevice(self.deviceId, 1, 0, sValue)
Code: Select all
if (Devices[Device].Units[Unit].nValue != nValue) or (Devices[Device].Units[Unit].sValue != sValue) or AlwaysUpdate:
Domoticz.Debug("Updating device '"+Devices[Device].Units[Unit].Name+ "' with current sValue '"+Devices[Device].Units[Unit].sValue+"' to '" +sValue+"'")
if isinstance(nValue, int):
Devices[Device].Units[Unit].nValue = nValue
else:
Domoticz.Log("nValue supplied is not an integer. Device: "+str(Device)+ " unit "+str(Unit)+" nValue "+str(nValue))
Devices[Device].Units[Unit].nValue = int(nValue)
Devices[Device].Units[Unit].sValue = sValue
if Name != "":
Devices[Device].Units[Unit].Name = Name
Devices[Device].Units[Unit].Update()