LUA || Qubino Dimmer || State "On" Topic is solved

Moderator: leecollings

Post Reply
timreijnen
Posts: 3
Joined: Sunday 09 April 2017 19:58
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

LUA || Qubino Dimmer || State "On"

Post by timreijnen »

Hi Guys,

Since this is my first post to the forum i apologize in advance for any faults or in-regulations.

I have my own house for a month now, so i can finally expand my hobby in domotica.. :D
I created the script below to automate some of the lighting in my house..

Code: Select all

-- Script voor het automatisch regelen van sommige verlichting in de avond en nacht.
--
-- Gemaakt door Tim Reijnen.
w=tonumber(otherdevices['Lichtsterkte Woonkamer']) --> De lichtsterkte van de woonkamer wordt opgelagen in variable 'w'
g=tonumber(otherdevices['Lichtsterkte Gang']) --> De lichtsterkte van de gang wordt opgelagen in variable 'g'
o=tonumber(otherdevices['Lichtsterkte Overloop']) --> De lichtsterkte van de overloop wordt opgelagen in variable 'o'
--
commandArray = {}
-- Gedeelte voor de verlichting in de woonkamer
if otherdevices['Iemand Thuis']=='On' then --> Als er iemand thuis is...
	if w <= 5 then --> En de lichtsterkte minder dan 5 lux is...
        if devicechanged['Beweging Woonkamer']=='On' then --> En er beweging is gedetecteerd in de woonkamer...
                commandArray['Plafondlamp Keuken']='Set Level 1' --> Doe ik ze aan voor jullie...
        end
    end
	if w <= 10 then --> En de lichtsterkte minder dan 10 lux is...
        if devicechanged['Beweging Woonkamer']=='On' then --> En er beweging is gedetecteerd in de woonkamer...
            if otherdevices['Lampen Televisie']=='Off' then --> En de lampen bij de televisie niet aan zijn...
                commandArray['Lampen Televisie']='On' --> Doe ik ze aan voor jullie...
            end
        end
	end
    if w > 5 then --> Als de lichtsterkte meer dan 5 lux is...
        if otherdevices['Plafondlamp Keuken']=='On' then --> En de lampen in de keuken zijn nog aan...
            commandArray['Plafondlamp Keuken']='Off' --> Doe ik die uit voor jullie...
        end
    end
	if w > 10 then --> Als de lichtsterkte meer dan 10 lux is...
	    if otherdevices['Lampen Televisie']=='On' then --> En de lampen bij de televisie nog aan zijn...
            commandArray['Lampen Televisie']='Off' --> Doe ik ze uit voor jullie...
        end
    end
end
if otherdevices['Iemand Thuis']=='Off' then --> Als er niemand (meer) thuis is...
    if otherdevices['Lampen Televisie']=='On' then --> En de lampen bij de televisie zijn nog aan.
        commandArray['Lampen Televisie']='Off' --> Doe ik ze uit...
    end
    if otherdevices['Plafondlamp Keuken']=='On' then --> En de lampen in de keuken zijn nog aan.
        commandArray['Plafondlamp Keuken']='Off' --> Doe ik ze uit...
    end
end
-- Gedeelte voor de verlichting in de gang
if g <= 10 then --> Als de lichtsterkte in de gang minder dan 10 Lux is...
    if otherdevices['Gang']=='Off' then --> En als de lamp in de gang nog uit is...
        commandArray['Gang']='Set Level 15' --> Doe ik de lamp vast gedimt aan...
    end
	if devicechanged['Beweging Gang']=='On' then --> En als er beweging is gedetecteerd in de gang...
        if uservariables['dagdeel']=='Middag' or uservariables['dagdeel']=='Avond' or uservariables['dagdeel']=='Ochtend' then --> En het middag, avond of ochtend is...
            commandArray['Gang']='Set Level 100' --> Doe ik de lamp daar even wat feller...
        end
        if uservariables['dagdeel']=='Nacht' then --> Maar als het nacht is...
            commandArray['Gang']='Set Level 35' --> Doe ik de lamp daar even wat feller, maar minder fel omdat het nacht is...
        end
    end
    if devicechanged['Beweging Gang']=='Off' then --> Als er geem beweging meer is gedetecteerd in de gang...
        commandArray['Gang']='Set Level 15' --> Dim ik daar de lamp weer...
    end
end
if g > 10 then --> Als de lichtsterkte in de gang meer dan 10 Lux is...
    if otherdevices['Gang']=='On' then --> En als de lamp in de gang nog aan is...
        commandArray['Gang']='Set Level 0' --> Doe ik die uit.
    end
end
-- Gedeelte voor de verlichting op de overloop
if o <= 10 then --> Als de lichtsterkte op de overloop minder dan 10 Lux is...
    if otherdevices['Overloop']=='Off' then --> En als de lamp op de overloop nog uit is...
        commandArray['Overloop']='Set Level 15' --> Doe ik de lamp vast gedimt aan...
    end
    if devicechanged['Beweging Overloop']=='On' then --> En als er beweging is gedetecteerd op de overloop...
        if uservariables['dagdeel']=='Middag' or uservariables['dagdeel']=='Avond' or uservariables['dagdeel']=='Ochtend' then --> En het middag, avond of ochtend is...
            commandArray['Overloop']='Set Level 100' --> Doe ik de lamp daar even wat feller...
        end
        if uservariables['dagdeel']=='Nacht' then --> Maar als het nacht is...
            commandArray['Overloop']='Set Level 35' --> Doe ik de lamp daar even wat feller, maar minder fel omdat het nacht is...
        end
    end
    if devicechanged['Beweging Overloop']=='Off' then --> Als er geem beweging meer is gedetecteerd op de overloop...
        commandArray['Overloop']='Set Level 15' --> Dim ik daar de lamp weer...
    end
end
if o > 10 then --> Als de lichtsterkte op de overloop meer dan 10 Lux is...
    if otherdevices['Overloop']=='On' then --> En als de lamp in de gang nog aan is...
        commandArray['Overloop']='Set Level 0' --> Doe ik die uit.
    end
end
My problem, better said challenge is this:

When it is light enough in various rooms (this is determined by the variables w,g and o) i want the system to turn off the lights again.
This work perfectly for the lights in my living room (w). I think because this is a dimmer, but switch mode is set to "On/Off".
However it doesn't work for the light in my hallway (g and o), probably because these two are set to switch type "Dimmer".

Through some debugging i found out that my problem is the if statement below, it doesn't match:
if otherdevices['Gang']=='On' then

Strange enough it does match when specified as "Off".. Could this be because if the light is dimmed the correct value is not "On"?

Any help would be appreciated.

Hardware: Qubino ZMNHDD1 Flush Dimmer
Software: Domoticz version: 3.7267 on a Raspberry Pi
Attachments
Dimmer, but switch type set to &quot;On/Off&quot;
Dimmer, but switch type set to "On/Off"
Screenshot from 2017-04-09 20-22-05.png (39 KiB) Viewed 951 times
Dimmer, and switch type set to &quot;Dimmer&quot;
Dimmer, and switch type set to "Dimmer"
Screenshot from 2017-04-09 20-22-19.png (37.3 KiB) Viewed 951 times
timreijnen
Posts: 3
Joined: Sunday 09 April 2017 19:58
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: LUA || Qubino Dimmer || State "On"

Post by timreijnen »

I found the actual value when the dimmer is dimmed.
Attachments
Screenshot from 2017-04-10 15-27-32.png
Screenshot from 2017-04-10 15-27-32.png (16.74 KiB) Viewed 937 times
timreijnen
Posts: 3
Joined: Sunday 09 April 2017 19:58
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: LUA || Qubino Dimmer || State "On"

Post by timreijnen »

the problem is caused by sometimes clicking on the lamp icon and sometimes sliding the dimmer balk.
When clicked on the icon the status goes to "On or Off"
When sliding the slider the status goes to "Set Level: 15 %"

I added the following code to tackle both ways..

Code: Select all

sg=tonumber(string.match(otherdevices['Gang'],"%d+")) --> Sla percentage van dimmer op in variabele 'sg'
if g > 10 then --> Als de lichtsterkte in de gang meer dan 10 Lux is...
    if sg==nil then --> als de variabele sg leeg is..
        if otherdevices['Gang']=='On' then
            commandArray['Gang']='Set Level 0'
        end
    else --> anders...
        if sg > 1 then --> En als de lamp in de gang nog aan is...
        commandArray['Gang']='Set Level 0' --> Doe ik die uit.
        end
    end
end
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest