Create Custom Counter in Python

Python and python framework

Moderator: leecollings

Post Reply
akamming
Posts: 369
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Create Custom Counter in Python

Post by akamming »

I am working on a plugin to connect my car to domoticz. One of the values i'd like to have in domoticz is the odometer. which should be of counter type with unit "km".

Current code to create/update that counter is:

Code: Select all

def UpdateCounter(vn,idx,name,value):
    if (not vn in Devices) or (not idx in Devices[vn].Units):
        Domoticz.Unit(Name=Parameters["Name"]+"-"+name, Unit=idx, Type=113, Switchtype=3, DeviceID=vin, Options="{'ValueQuantity': 'Distance','ValueUnits': 'km'}",Used=True).Create()
    Devices[vin].Units[idx].nValue = value
    Devices[vin].Units[idx].sValue = value
    Devices[vin].Units[idx].Update(Log=True)
    Domoticz.Log("Counter ("+Devices[vin].Units[idx].Name+")")
Counter is created and works. However unit is not set to "km" (it is empty). The countertype of unit km works, cause I can change manually using the UI, but ofcourse like to automate this in python.

So what is the correct code for creating a counter with "km" as unit?
akamming
Posts: 369
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Create Custom Counter in Python

Post by akamming »

akamming wrote: Wednesday 03 May 2023 20:48 I am working on a plugin to connect my car to domoticz. One of the values i'd like to have in domoticz is the odometer. which should be of counter type with unit "km".

Current code to create/update that counter is:

Code: Select all

def UpdateCounter(vn,idx,name,value):
    if (not vn in Devices) or (not idx in Devices[vn].Units):
        Domoticz.Unit(Name=Parameters["Name"]+"-"+name, Unit=idx, Type=113, Switchtype=3, DeviceID=vin, Options="{'ValueQuantity': 'Distance','ValueUnits': 'km'}",Used=True).Create()
    Devices[vin].Units[idx].nValue = value
    Devices[vin].Units[idx].sValue = value
    Devices[vin].Units[idx].Update(Log=True)
    Domoticz.Log("Counter ("+Devices[vin].Units[idx].Name+")")
Counter is created and works. However unit is not set to "km" (it is empty). The countertype of unit km works, cause I can change manually using the UI, but ofcourse like to automate this in python.

So what is the correct code for creating a counter with "km" as unit?
I noticed no answer. I also see a lot less answers than a few years ago on the forum on these kind of questions. When i started hobbying on domoticz if i asked these kind of dev support questions to the community i always got quick responese. Now it appened to me now several times that i had to wait for days, or didn't get an answer at all... Is this a symptom of the community thinning out?

(no accusation! very grateful for all the hard work for every volunteer who helps here. Try to do my part as well.. but if the community is thinning out it is something i have to take into account. With my home depending more and more on the support of the domoticz community it might be time for thinking about alternate solutions with a more active dev community)
skippy711
Posts: 32
Joined: Friday 20 January 2017 17:52
Target OS: NAS (Synology & others)
Domoticz version: 2024.2
Location: Netherlands
Contact:

Re: Create Custom Counter in Python

Post by skippy711 »

Hi there,
I'm afraid I can't help with your question with the plugin.
I do recognize your observation on answers taking longer or not coming at all. When I started back in 2017 I found a lot of answers on my questions so no need to ask for myself. Meantime I experimented my way through al lot of new developments and everything is running flawless for months, I which was certainly not my experience in 2018-2020. Maybe that also had to do with the mini PC I used in those years. I remember another user here on the forum stating that Domoticz was kind of boring because nothing was going on and at the same time appreciating the fact that boring is reliable which has its advantages (Wife Acceptance Factor and so on). I feel kind of the same: on one hand having a reliable setup with no frustrations is very comfortable but on the other hand I started tinkering with these systems/programs because I feel sort of a Tweaker and when there is nothing to tweak I might lose interest and find a new tinkertoy.
Good luck on whatever choice you make!
akamming
Posts: 369
Joined: Friday 17 August 2018 14:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Create Custom Counter in Python

Post by akamming »

Thanx..

the good news is: I found the solution by reverse engineering how the code works and the answer is:
- You can create a custom counter with a custom unit in the python plugin framework by setting
- DeviceType to 113
- Switchtype to 3
- and options to {"ValueQuantity": "Custom", "ValueUnits": "<whatever you unit is>"}

been checking the forum on questions like this and came to the conclusion it's not just me. These kind of questions were answered in the past but not a lot of response now. I really like domoticz. So don't want to switch to something else. But do hope community support will be better.

Anyway since this feature was undocumented: I just added it to the wiki.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest