Page 1 of 2

After migrate/reinstall cleanup

Posted: Sunday 01 June 2025 9:52
by Varazir
Hello,

I just reinstalled my pi and then I switched to all docker setup with zigbee/zwave/MTT/Domoticz.

Now I see this, what's the easiest way to merge the new found devices? Do it in domoticz or change in zigbee ?
Why did Domoticz create new devices to start with ?
Image

-------------------------------------

I lost data for my Philips lux sensor, how can I restore it from backup db file?
I tried to use the replace command, it should be a merge command not replace as in 99% you want to keep the data.
There should be a question asking what device to keep.
Not first time I mess it upp. Confusing function.

-------------------------------------

I get this message in the loggs

Code: Select all

2025-06-01 09:36:38.889 dzVents: IKEARemote: ------ Start internal script: IKEA - Remote: Device: "IKEA Remote_toggle (Zigbee2MQTT)", Index: 468
2025-06-01 09:36:38.893 dzVents: Debug: IKEARemote: Processing device-adapter for RemoteDummyDimmer: Switch device adapter
2025-06-01 09:36:38.894 dzVents: IKEARemote: Unknown action requested; ignored
2025-06-01 09:36:38.894 dzVents: IKEARemote: ------ Finished IKEA - Remote
This is the script I'm using ( Got help here to built it )

Code: Select all

--
-- Creater Varazir ( And big help from waaren and others on domotiz forum )
-- e-mail: varazir .. gmail.com
-- Version: 1.5
--
-- groups = {'group1', 'group2', 'group3', 'group4', 'group5', 'group6', 'group7' }

return  {
    on =        {
                    devices         = { '*IKEA Remote*' }
                },

    logging =   { 
                    level           = domoticz.LOG_DEBUG, 
                    marker          = "IKEARemote" 
                },

    data =      { 
                    currentGroup    = { initial = 1 }
                }, 

    execute = function(dz, item)
        local function logWrite(str,level)
            dz.log(tostring(str),level or dz.LOG_DEBUG)
        end
        
        control = 
        {
            'Taklampa Sovrum',
            group1 =
            { 
                IKEAlamp        = { idx = 287, toggle = true, blink = true, dimmer = true}
            },
            'Uttag Sovrum',
			group2 =
            { 
                IKEAOutlet         = { idx = 217, toggle = true, blink = true }, 
            },
            'Rullgardin Sovrum',
			group3 =
            { 
                Blinder         = { idx = 59, toggle = true, blinder = true },
            },
            
            'Taklampa Hall',
            group4 =  
            {
                IKEAlamp        = { idx = 292, toggle = true, blink = true, dimmer = true },
                IKEAlampGrupp   = { idx = 308, toggle = true, blink = false, dimmer = true },
			},
            
            'Taklampa Datorrum',
			group5 =
            { 
                IKEAlamp        =  { idx = 290, toggle = true, blink = true, dimmer = true}
            },
            
            'Taklampa Vardagsrum',
            group6 =
            { 
                IKEAlamp   = { idx = 304, toggle = true, blink = true, dimmer = true } 
            },
            
            'TVbänk',
			group7 = 
            { 
                Lamp            = { idx = 42, toggle = true, blink = true},
                TvGroup         = { idx = 2,  toggle = true, group = true}
            },
            
            'Rullgardin Vardagsrum',
			group8 =
            { 
                Blinder         = { idx = 83, toggle = true, blinder = true }, 

            },
        }

        local selectedGroupNumber = dz.data.currentGroup
        local maxGroup = #control
        local dummyDimmer = dz.devices(82)

        local function doAction(action, direction)
            logWrite("10 Current group number........" .. selectedGroupNumber)
            selectedGroup = "group" .. selectedGroupNumber

            logWrite("11 Current selected group is..." .. selectedGroup)
            selectedControlGroup = control[selectedGroup]

            logWrite("12 Selected Control Group is a " .. type(control[selectedGroup]))
            
            switchSelectorGroupNumber = math.floor( selectedGroupNumber * 10)
            logWrite("13 Selected switchSelectorGroupNumber " ..  switchSelectorGroupNumber)
            dz.devices('IKEA Remote Groups').switchSelector(switchSelectorGroupNumber).silent()

            for device, attributes in pairs(selectedControlGroup) do
                logWrite("20 Current device is........." .. device)
                logWrite("21 Attribute type is........." .. type(attributes))
                logWrite("22 IDX is...................." .. attributes["idx"])
                currentIDx = attributes["idx"]
                
                if attributes["group"] then
                    logWrite("24 Current Device is group......." .. dz.groups(currentIDx).name)
                    currentDevice = dz.groups(currentIDx)
                else
                    logWrite("25 Current Device is device......" .. dz.devices(currentIDx).name)
                    currentDevice = dz.devices(currentIDx)
                end
                
                for attribute, value in pairs(attributes) do
                    logWrite("30 Current attribute is......" .. device)
                    if attribute == action then
                        logWrite("31 Current acction is......" .. action)
                        -- Blinking 
                        if action == 'blink' then
                            local blinkDevice = currentDevice
    						local blinkLevel = currentDevice.level
    						-- dz.utils.dumpTable(blinkDevice)
    						-- dz.utils.dumpTable(attributes)
    						logWrite("Device " .. blinkDevice.name .. " will blink")
    						if blinkDevice.state == "Off" then 
    							blinkDevice.switchOn()
    							blinkDevice.switchOff().afterSec(0.5)
    						else
    							blinkDevice.switchOff()
    							blinkDevice.switchOn().afterSec(0.5)
    						end
    						
    			        elseif action == 'dimmer' then 
    						local dimDevice = currentDevice
    						local dimLevel = dimDevice.level
    						local delay = 0
                            logWrite(dimDevice.name .. " direction is " .. direction)
    						if direction == "stop" then 
    						    dimDevice.cancelQueuedCommands()
    						    logWrite('Stop dimming of ' .. dimDevice.name .. ' at ' .. dimLevel ..'%')
    						elseif direction == 'down' then
    							repeat
    								delay = delay + 0.1
    								dimLevel = dimLevel - 1
    								logWrite('Set ' .. dimDevice.name .. ' to dimLevel '.. dimLevel .. '%, after ' .. delay .. ' seconds')
    								dimDevice.dimTo(dimLevel).afterSec(delay)
    							until dimLevel <= 0
    					    elseif direction == 'up' then
                                repeat
                                    delay = delay + 0.1
                                    dimLevel = dimLevel + 1
                                    logWrite('Set ' .. dimDevice.name .. ' to dimLevel '.. dimLevel .. '%, after ' .. delay .. ' seconds')
                                    dimDevice.dimTo(dimLevel).afterSec(delay)
                                until dimLevel >= 100
    						end
                        elseif action == 'toggle' then
                            -- dz.utils.dumpTable(currentDevice)
                            -- dz.utils.dumpTable(attributes)
                            local toggleDevice = currentDevice
                            if attributes["group"] then
                                toggleDevice.toggleGroup()
                            else 
                                toggleDevice.toggleSwitch()
                            end
                        end
                    end
                end
            end
        end
        
        local action = 'blink'
        local direction = 'up'
        
        if item.state == 'Click' and item.name == '$IKEA Remote Left' then 
            selectedGroupNumber = selectedGroupNumber - 1 
            if selectedGroupNumber == 0 then selectedGroupNumber = maxGroup end
            dz.notify("Aktuell grupp",control[selectedGroupNumber],dz.PRIORITY_NORMAL,dz.NSS_HTTP)
        elseif item.state == 'Click' and item.name == '$IKEA Remote Right' then 
            selectedGroupNumber = selectedGroupNumber + 1 
            if selectedGroupNumber > maxGroup then selectedGroupNumber = 1 end
            dz.notify("Aktuell grupp",control[selectedGroupNumber],dz.PRIORITY_NORMAL,dz.NSS_HTTP)
        elseif item.name == '$IKEA Remote New' then
            action = 'toggle'
        elseif item.state == 'Hold' and item.name == "$IKEA Remote Up"  then
            action = 'dimmer'
        elseif item.state == 'Hold' and item.name == '$IKEA Remote Down' then
            action = 'dimmer' 
            direction = 'down'
        elseif item.state == 'Release' and item.name == '$IKEA Remote Down' or item.name == '$IKEA Remote Up' then
            action = 'dimmer'
            direction = 'stop'
        elseif item.name == '$IKEA Remote Groups' then 
            selectedGroupNumber = math.floor( item.level/10 )
            logWrite("00 Group selected with IKEA Remote Groups" .. selectedGroupNumber)
        else
            logWrite('Unknown action requested; ignored', dz.LOG_INFO )
            return
        end
        
        if item.state == 'Click' or item.state == 'Release' then 
            logWrite('Turning off ' .. item.name)
            dz.devices(item.name).switchOff().silent()
        end
        
        dz.data.currentGroup = selectedGroupNumber
        doAction(action, direction) 
        
        
    end
}

Re: After migrate/reinstall cleanup

Posted: Sunday 01 June 2025 21:29
by Varazir
I have few DB entries that are messed up as well, I didn't use that much.

Image

Re: After migrate/reinstall cleanup

Posted: Monday 02 June 2025 20:48
by Varazir
I added my html files to the template folder but I can't see the custom menu button, was there a setting ?

Image


Image

Re: After migrate/reinstall cleanup

Posted: Tuesday 03 June 2025 14:20
by gizmocuz
Did you restart Domoticz?

Re: After migrate/reinstall cleanup

Posted: Tuesday 03 June 2025 15:13
by Varazir
gizmocuz wrote: Tuesday 03 June 2025 14:20 Did you restart Domoticz?
yes even moved it to get a new Ikea lamp bulb to connect.
I restarted it several times while I as TS everything ells.

Re: After migrate/reinstall cleanup

Posted: Tuesday 03 June 2025 16:29
by gizmocuz
Strange folder... ~/domoticz/data/www/templates... should this not be ~/domoticz/www/templates ?

Re: After migrate/reinstall cleanup

Posted: Tuesday 03 June 2025 17:48
by Varazir
gizmocuz wrote: Tuesday 03 June 2025 16:29 Strange folder... ~/domoticz/data/www/templates... should this not be ~/domoticz/www/templates ?
I'm running docker installation. It's why the path looks strange.

Re: After migrate/reinstall cleanup

Posted: Wednesday 04 June 2025 13:28
by gizmocuz
That is indeed strange, but did you map a folder to the template folder inside the docker like:

Code: Select all

    volumes:
      - ./config:/opt/domoticz/userdata
      - ./config/www/templates:/opt/domoticz/www/templates
next you can place the files in your ./config/www/templates folder

Re: After migrate/reinstall cleanup

Posted: Wednesday 04 June 2025 17:51
by Varazir
gizmocuz wrote: Wednesday 04 June 2025 13:28 That is indeed strange, but did you map a folder to the template folder inside the docker like:

Code: Select all

    volumes:
      - ./config:/opt/domoticz/userdata
      - ./config/www/templates:/opt/domoticz/www/templates
next you can place the files in your ./config/www/templates folder
Hmm,

Didn't see anything about that here https://wiki.domoticz.com/Docker
No I didn't map the templates folder.

Edit: It helped thanks. One thing fixed on my issue list.

Re: After migrate/reinstall cleanup

Posted: Wednesday 04 June 2025 18:08
by Varazir
How can I restore data that is gone if I do it wrong ? ( I have a backup DB with all history)

Re: After migrate/reinstall cleanup

Posted: Wednesday 04 June 2025 21:32
by Varazir
Starting to nesting it up, the creation of new devices sucks. I hided several devices so I need go and rename them all and the replace then hide them again.

Re: After migrate/reinstall cleanup

Posted: Thursday 05 June 2025 7:50
by gizmocuz
If you get new devices for your previous ones (because you switched from openzwave to zwavejs for example), you can press edit on your old device, and press the 'Replace' button and select the new one
So rename the new one to 'temp1_new', then press edit on 'temp1' and replace it with 'temp1_new', all history,timers,events everything stays the same

Yes you have to do this once

Re: After migrate/reinstall cleanup

Posted: Thursday 05 June 2025 7:56
by Varazir
gizmocuz wrote: Thursday 05 June 2025 7:50 If you get new devices for your previous ones (because you switched from openzwave to zwavejs for example), you can press edit on your old device, and press the 'Replace' button and select the new one
So rename the new one to 'temp1_new', then press edit on 'temp1' and replace it with 'temp1_new', all history,timers,events everything stays the same

Yes you have to do this once
This time it was from Docker to Docker but z2m was updated to v2 in the process.

Example this was the ID of the old device 0x90fd9ffffee8004b_action_zigbee2mqt
This was what Domoticz added after I reinstalled 0x90fd9ffffee8004b_identify_zigbee2mqtt

I have replaced the devices that needed to be replaced so that is in order now. I guess I'll find more to replace later but now I'm confident how it works.

Next is as I said some DB hacking to even out the history of some devices.

Re: After migrate/reinstall cleanup

Posted: Thursday 05 June 2025 8:05
by gizmocuz
So you did not replace them via the 'Replace' button/option? Database hacking is never a good idea.

I also have device with a 'identify' , but here it is an airsensor from ikea.
This button is not needed as it is for internal usage only (to pair it)

All my other switches stayed the same

Re: After migrate/reinstall cleanup

Posted: Thursday 05 June 2025 22:57
by Varazir
gizmocuz wrote: Thursday 05 June 2025 8:05 So you did not replace them via the 'Replace' button/option? Database hacking is never a good idea.

I also have device with a 'identify' , but here it is an airsensor from ikea.
This button is not needed as it is for internal usage only (to pair it)

All my other switches stayed the same
yes I have always used replace function but it's not clear if I should do it on the new or old device. So I wiped the data from my Philips Lux sensor.
I restored the data using python script.

In this case it was Ikea 5 button controller, one of the first they made for zigbee and all buttons got a new ID.
And it was the center button that got the identify tag.

Oh well I just have the spikes on some of the meters to fix now and I have done that before. Looks easy in SQLlite program
I had this before the reinstallation.

Re: After migrate/reinstall cleanup

Posted: Thursday 05 June 2025 23:14
by Varazir
There should be a option replace in the device list.

Another example on new device just by upgrading the z2m docker

Image

Re: After migrate/reinstall cleanup

Posted: Friday 06 June 2025 10:02
by Varazir
gizmocuz wrote: Thursday 05 June 2025 8:05 So you did not replace them via the 'Replace' button/option? Database hacking is never a good idea.

I also have device with a 'identify' , but here it is an airsensor from ikea.
This button is not needed as it is for internal usage only (to pair it)

All my other switches stayed the same
Something is wrong here or changed in a way that I need to re do all my automations and setup.
I have this 2 devices the 307 is my old before reinstallation working device and a new have been added. Now the old Just turns the device on and off.
I replace the old with the new, then the button keep turn on and off the device all time and next time I disable and enable the z2m hardware the new device getting added back again.
Image

Re: After migrate/reinstall cleanup

Posted: Friday 06 June 2025 10:05
by gizmocuz
If you replace the 'switch' one (press edit in the light/switches page on this switch, make sure the IDX reads 307), press 'Replace' and select the new one (maybe rename the new one (569) to _new so you know you select the right one)
When you then go back into the devices overview, you should only see 307, and the ID should read *_identify_* instead of *_switch_*

Re: After migrate/reinstall cleanup

Posted: Friday 06 June 2025 10:14
by Varazir
gizmocuz wrote: Friday 06 June 2025 10:05 If you replace the 'switch' one (press edit in the light/switches page on this switch, make sure the IDX reads 307), press 'Replace' and select the new one (maybe rename the new one (569) to _new so you know you select the right one)
When you then go back into the devices overview, you should only see 307, and the ID should read *_identify_* instead of *_switch_*
Ok,
Before
Image

Replaced
Image

After
Image

After I updated the z2m hardware
Image


Still it's only the new device that works, the old keeps turning the device on and then off again.
And I think identify is now used for be able to reset the device remotely.

Re: After migrate/reinstall cleanup

Posted: Friday 06 June 2025 10:18
by Varazir
LOL I hade bloky/event turning it off stupid me :)