Create your own device adapter

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
henkkoorn
Posts: 4
Joined: Sunday 12 February 2023 11:53
Target OS: Linux
Domoticz version: 2023.1
Location: Huizen, Nederland
Contact:

Create your own device adapter

Post by henkkoorn »

Hello,
i am trying to make my own device adapter
like for current there is an adapter for 1 phase and also for 3 phase
there is already an adapter for voltage and now I want to make a new adapter for 3 phase voltage and one 3 phase power.

the documentation explains 'Create your own device adapter'
Create your own device adapter

If your device is not recognized by dzVents, you can still operate it using the generic device attributes and methods. It is much nicer, however, to have device specific attributes and methods. Existing recognized adapters are in /path/to/domoticz/dzVents/runtime/device-adapters. Copy an existing adapter and adapt it to your needs. You can turn debug logging on and inspect the file domoticzData.lua in the dzVents folder. There you will find the unique signature for your device type. Usually it is a combination of deviceType and deviceSubType, but you can use any of the device attributes in the matches function. The matches function checks if the device type is suitable for your adapter and the process function actually creates your specific attributes and methods. Also, if you call myDevice.dump() you will see all attributes and methods and the attribute _adapters shows you a list of applied adapters for that device. Finally, register your adapter in Adapters.lua. Please share your adapter when it is ready and working.
i have given the new adapter the following name 'voltage_3_phase_device'
and placed in the folder: /path/to/domoticz/dzVents/runtime/device-adapters
and also Adapted Adapters point lua

Code: Select all

return {
        baseType = 'device',
        name = '3-phase Voltage device adapter',
        matches = function(device, adapterManager)
                local res = (device.deviceType == 'Voltage' and device.deviceSubType == 'CM113, Electrisave')
                return res
        end,
        process = function(device, data, domoticz, utils, adapterManager)

                device.voltage1 = tonumber(device.rawData[1])
                device.voltage2 = tonumber(device.rawData[2])
                device.voltage3 = tonumber(device.rawData[3])

                function device.updateVoltage(voltage1, voltage2, voltage3)
                        return device.update(0, tostring(voltage1) .. ';' .. tostring(voltage2) .. ';' .. tostring(voltage3) )
                end
        end
}
but now ? I thought 'I'm making a new virtual sensor' but there is no difference in the list of sensor types
what have I missed ? what am i not doing right?
Attachments
voltage_3_phase_device.lua.zip
(469 Bytes) Downloaded 23 times
Last edited by henkkoorn on Tuesday 18 April 2023 19:21, edited 3 times in total.
User avatar
waltervl
Posts: 5736
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Create your own device adapter

Post by waltervl »

The DzVents device adapters are used to make special DzVents device functions like .counterDeliveredToday() available for existing Domoticz devices.
So have nothing to do with creating devices.
If you need to create a 3 phase voltage virtual device and it is not in the drop down list you need to add it in the source code or find the device details and create it manually with http API json call: https://www.domoticz.com/wiki/Domoticz_ ... e_a_device

As this is a new device it perhaps could not be in the list and you need to go to the source code (as mentioned in the API documentation)

Edit: I do not think there is a 3 phase Voltage domoticz device yet. So if you need to make that you need to add it to the domoticz source code.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
henkkoorn
Posts: 4
Joined: Sunday 12 February 2023 11:53
Target OS: Linux
Domoticz version: 2023.1
Location: Huizen, Nederland
Contact:

Re: Create your own device adapter

Post by henkkoorn »

Thank you for the quick reply
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest