Define a max reach value of a dimmer at certain hours

Hi,

I have a lot of issues to do following script in a scene:

1/I do the folowing script in luup of the scene (with night condition to test it at first)

if (luup.is_night()) then
local service_id = “urn:upnp-org:serviceId:Dimming1”
local dim_status = luup.variable_get(service_id,“LoadLevelStatus”, 118)
if (tonumber(dim_status) > 51) then
luup.call_action(service_id, “SetLoadLevelTarget”, {newLoadlevelTarget = “50”}, 118)
return true
else
return false
end
end

2/ In the event: trigger when the switch 118 go on et command the 118 set level to 50%

3/ All works but only one time at the beginning of the scene with switch on, go to 100% and dimme immediatly to 50%

How can I do to watch the change of the dimmer value if it is over 51% then trigger the scene?
I dont want to watch only the swith but the dimmervalue because it can be change with a remote control
I try this in the event luup code:

local dim_status = luup.variable_get(service_id,“LoadLevelStatus”, 118)
if (tonumber(dim_status) > 51) then
return true
else
return false
end

but it doesnt work…

Thanks for help,

[i]RichardTSchaefer

Hero Member
*****
Posts: 515
    Email

Re: Fix Dimming at certain time of a day
« Reply #5 on: January 02, 2013, 03:09:26 pm »

Quote

Quote

1/ Is it possible to activate the scene every second, or always (every 0,1s)?

The luup internal timer can schedule at a 1 second interval … But that eats up a lot of processing time! That’s probably why MCV did not bring this out to the user interface.

Quote

2/ How is it possible to create an event in a scene like this:

Actually your LUUP code does not create an event. An event happens (timer or trigger).
You can put code in the LUUP tab for the scene that causes the timer or trigger to be ignored.
If the code returns TRUE or does not return anything than it proceeds to execute the commands (and delayed commands) for your scene.[/i]

Hi,

Thanks for reply,

I created than a virtual state device 125

I create a code in a scene like this to set this device at 1 if dimmer more than 51%:

local dim_status = luup.variable_get(“urn:upnp-org:serviceId:Dimming1”, “LoadLevelStatus”, 118)

if dim_status>51 then
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },125)
end

but i have the same problem, the device is not set to 1 if dimmer >51, normally the code of every scene must be read and execute or not?

Is it really not possible in MCV to do something like this?

Hi,

I found a solution, I programm Logic Controller in the industry with Allen Bradley Control Logix or Siemens an it s very more easier as with MCV.
Sure MCV is cheaper …

I create to virtual device trigger 1 and trigger 2.
I create two scenes with
scene 1 command trigger 2 ON and after 5s OFF, only when events Trigger 2 OFF or LAMP ON
scene 2 command trigger 1 ON and after 5s OFF, olny when events Trigger 1 OFF

Result: I created a SET RESET Function automatically every 5 seconde between trigger 1 and 2, it s like a clock 5 second ON and 5 second OFF for the trigger.

I associate in the luup only between 20h00 and 23h00.

So i can control every 5s the dimmer of my lamp, when it s over 51% I reduce to 50%.

It s better for me like the every 1 minutes of the camendar events

Thanks for all for reading me and to the next time,

Balez1

Hello

Not sure if it solves your problem, but try looking at the luup function “variable_watch”.

If you put it in the startup lua (under MiOS developers) it will run continuously in the background. I’m using it to make sure that my dimmers only reach a certain level after sunset. The code fires everytime the dimmer level is adjusted whether by script, remote, or switch.

Here is an extract from my startup lua, pardon the inelegance of my use of the language – I’m both a lazy script writer when not being paid and still learning!!

In the example below, Switch device 47 that gets assigned to lul_tmp is a virtual switch that allows you to turn power-saving mode for the house on or off globally.

I chose 51% not 50% as the target to allow the value to act as a flag in the morning so the house knows if the light is only coming up to a level set by power saving (in which case it will drive it up to 100% automatically). I figured it was unlikely anyone would set the lights to 51% precisely manually on the dimmers.


function no_dimming_50 (lul_device, lul_service, lul_variable, lul_value_old, lul_value_new)
local lul_tmp = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, 47)

if ((lul_tmp == “1”) and (luup.is_night()) and (tonumber(lul_value_new) > 51)) then
local lul_arguments = {}
lul_arguments[“newLoadlevelTarget”] = 51
lul_resultcode, lul_resultstring, lul_job, lul_returnarguments = luup.call_action(“urn:upnp-org:serviceId:Dimming1”,“SetLoadLevelTarget”, lul_arguments,lul_device)
end

if ((lul_tmp == “1”) and (luup.is_night() == false) and (tonumber(lul_value_new) == 51)) then
local lul_arguments = {}
lul_arguments[“newLoadlevelTarget”] = 100
lul_resultcode, lul_resultstring, lul_job, lul_returnarguments = luup.call_action(“urn:upnp-org:serviceId:Dimming1”,“SetLoadLevelTarget”, lul_arguments,lul_device)
end

end

luup.variable_watch (‘no_dimming_50’, ‘urn:upnp-org:serviceId:Dimming1’, ‘LoadLevelStatus’, 21)


Paul