deleting sensor data from plugin <updated>

Python and python framework

Moderator: leecollings

Post Reply
JanJaap
Posts: 215
Joined: Thursday 12 October 2017 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Dev
Location: the Netherlands
Contact:

deleting sensor data from plugin <updated>

Post by JanJaap »

Hey,

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()
Updating like this:

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)
With the rlevant bits of UpdateDevice being:

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()
Running on Debian Bullseye, Dev version of Domoticz on RPI 3B
RPi 3, Domoticz dev version, Aeon ZWave stick (with a whole bunch of slaves), Zigbee using Zigbee2MQTT, Nest thermo, P1 smart meter on RPi Zero
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest