Page 1 of 1

Dimmer Mode: Extend Devices attributes stored on User Variable

Posted: Thursday 17 August 2017 12:01
by solidum90
Hello to everyone,
It's been a while since I'm working on domoticz to make my home smart (I live alone, at least one intelligent at home will have to be :D)
I managed through my own web service Vimar By-Me home automation system (it use an IEB bus with a proprietary protocol very similar to KNX).
Everything works well, now I'm trying to increase the functionality by adding a double touch fuction on the wall buttons (standard Vimar) to activate the "double tap mode" (if you tap 2 times ON/OFF Button within two seconds) in addition to the classic ON / OFF buttons, via LUA script.

It already works with scene, with "double tap mode" you can activate a specific scene for ON or OFF button, It's cool :D
I would like to extend the functionality even in "Dimmer mode", then by pressing the first time in "double mode", set brightness at 25%, then at 50-75-100, at the end of the change cycle, change cold to warm white and vice versa (I have milight lights RGB+CCT).

The only problem in all this it'is know the previous state I was left, I can't see from devicechanged[devicename] or otherdevices[devicename] (there is there another way ??)

So I would to save state when I change it in a user variable string as xml/json/whatever where dynamically set/get the last state set for device.
Do you know some library that I can use (I'm not very practicing in lua), or some other way to do what I want?

I attach part of my actual code if someone is interested.

Code: Select all

function timedifference(timestamp)
  y, m, d, H, M, S = timestamp:match("(%d+)-(%d+)-(%d+) (%d+):(%d+):(%d+)")
  difference = os.difftime(os.time(), os.time{year=y, month=m, day=d, hour=H, min=M, sec=S})
  return difference
end

SecondFunction = {};
SecondFunction[1] = {button="Camera", 
                            SecondFunctionON_Type = "Scene", SecondFunctionON_Action = "Illumina Letto",
                            SecondFunctionOFF_Type = "Scene", SecondFunctionOFF_Action="Spegni Camera"}

SecondFunction[2] = {button="Living", 
                            SecondFunctionON_Type = "Dimmer", SecondFunctionON_Action = "<none>",
                            SecondFunctionOFF_Type = "<none>", SecondFunctionOFF_Action=""}
                            
commandArray = {}

-- verifico tutte le seconde funzioni configurate

for i, v in pairs(SecondFunction) do
    
    if(devicechanged[v.button]) then
        
        if(timedifference(otherdevices_lastupdate[v.button]) < 2 ) then
            
            print("Stato Seconda funzione: "..otherdevices[v.button]);
            
            if(devicechanged[v.button] == "On" or  devicechanged[v.button] == "Set Kelvin Level" or devicechanged[v.button] == "Set Level") then
                
                print ("Seconda funzione ON button = ".. v.button ..": Tipo Azione ="..v.SecondFunctionON_Type..", Azione = "..v.SecondFunctionON_Action);
                
                if(v.SecondFunctionON_Type == "Scene") then
                    print("Attivo Scena = "..v.SecondFunctionON_Action);
                    commandArray["Scene:"..v.SecondFunctionON_Action] = "On";
                elseif (v.SecondFunctionON_Type == "Dimmer") then
                    --print("Stato attuale: "..devicechanged[v.button]);
                    
                    if(otherdevices[v.button] == "On") then
                        commandArray[v.button] = "Set Kelvin Level";
                    elseif(otherdevices[v.button] == "Set Kelvin Level") then
                        commandArray[v.button] = "Set Level 75";
                    elseif(otherdevices[v.button] == "Set Level") then
                        commandArray[v.button] = "On";
                    end
                end
                
            elseif(devicechanged[v.button] == "Off") then 
                
                 print ("Seconda funzione OFF button = ".. v.button ..": Tipo Azione ="..v.SecondFunctionOFF_Type..", Azione  = "..v.SecondFunctionOFF_Action);
                 
                if(v.SecondFunctionOFF_Type == "Scene") then
                    print("Attivo scena "..v.SecondFunctionOFF_Action);
                    
                    commandArray["Scene:"..v.SecondFunctionOFF_Action] = "On";
                elseif (v.SecondFunctionOFF_Type == "Dimmer") then
                    print("Stato attuale: "..devicechanged[v.button]);
                end
            end
        end
        
    end
end
Thanks a lot, congratulations or great project! :)