Inventory of devices

Subforum for general discussions. Do not dump your questions/problems here, but try to find the subforum where it belongs!

Moderators: leecollings, remb0

Post Reply
peterbos
Posts: 93
Joined: Saturday 07 November 2020 21:41
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Inventory of devices

Post by peterbos »

Hi,

I want to make a csv file with an inventory of all devices in Domoticz. I wrote a dzVents script that finds all devices that are shown (used) on the tabs but not the ones that are hidden (unused) from the tabs:

Code: Select all

return {
    active = true, -- Activeer het script
    on = {
        timer = { 'every minute' } -- Voer het script elk uur uit (of pas dit naar wens aan)
    },
    execute = function(domoticz)
        -- Bestandspad waar de CSV wordt opgeslagen
        -- Open het bestand voor schrijven
        local file = io.open("/mnt/documents/Domoticz/apparaten.csv", "a+")

        if file then
            -- Schrijf de header van het CSV-bestand
            file:write('DeviceID;Name;Type;Hardware\n')

            -- Doorloop alle apparaten in Domoticz
            for i = 1, 250 do
                -- Haal apparaatdetails op
                if domoticz.utils.deviceExists(i) then
                    local device = domoticz.devices(i)
                    local deviceID = device.id
                    local name = device.name
                    local deviceType = device.deviceType
                    local hardware = device.hardwareName
                    -- Schrijf de gegevens naar het CSV-bestand
                    local s = deviceID .. ';' .. name ..';'.. deviceType ..';'.. hardware ..';'..'\n'
                    file:write(s)
                end
            end

            -- Sluit het bestand
            file:close()
        end
    end
}
How can I get the complete list of all devices, used or not used? A complete approach to get a csv file is also good.

Peter
HvdW
Posts: 531
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Inventory of devices

Post by HvdW »

Try this and look in the log.

Code: Select all

return {
    on = {
        devices = {'YourSwitch', 'YourSwitchSelector'}, 
        -- or timer = {'every 1 minutes'}
    },
    logging = {
        level = domoticz.LOG_INFO,
        marker = "Alle apparaten"
    },
    execute = function(domoticz)
        domoticz.devices().forEach(function(device)
            domoticz.log('Device ID: ' .. device.id .. ', Name: ' .. device.name .. ', Type: ' .. device.deviceType .. ', Hardware: ' .. device.hardwareName, domoticz.LOG_INFO)
        end)
    end
}
For experimenting I'm using YourSwitch and YourSwitchSelector to activate a test script.
Bugs bug me.
User avatar
waltervl
Posts: 5384
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Inventory of devices

Post by waltervl »

Why would you want that csv/Excel file on a regular base?
If it is just for one time copy the contents of page Setup - Devices with old fashioned select copy/paste into an Excel file.
Or open a recent database backup with sqlite browser and copy the contents of the device tables.
Another alternative is to use an API call for all devices and paste the resulting json in an Excel.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
gizmocuz
Posts: 2394
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Inventory of devices

Post by gizmocuz »

Agreed, just use the JSON API to retrieve the list of devices/state in JSON and import this in Excel
Quality outlives Quantity!
peterbos
Posts: 93
Joined: Saturday 07 November 2020 21:41
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Inventory of devices

Post by peterbos »

I used the JSON API call '/json.htm?type=command&param=getdevices&displayhidden=1'. In the wiki it also contains '&used=true' but if you add that it will filter out all unused devices. If you add '&used=false' it filters out all used devices. If you omit it, it does not filter and gives all devices. I converted the json file with an online converter to a csv file.

Thanks!
Peter
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest