Page 1 of 1

if time set color

Posted: Wednesday 04 September 2019 22:43
by Gianni
Hello

looking for someone to help me.
I got a lua when sensor triggered a light go on(thx to this forum :-) )
Now i want if time between 18.00 en 06.00 the light is blue en dim to 50 and between 06.01 en 17.59 white and 100.
I got the json and this works when enteren manual but i can not get it work in a script.

json call blue = http://ipadres:port/json.htm?type=command&param=setcolbrightnessvalue&idx=93&color={%22m%22:3,%22t%22:0,%22r%22:0,%22g%22:1,%22b%22:255,%22cw%22:0,%22ww%22:0}&brightness=50

json call white = http://ipadres:port/json.htm?type=command&param=setcolbrightnessvalue&idx=93&color={%22m%22:2,%22t%22:0,%22r%22:0,%22g%22:0,%22b%22:0,%22cw%22:255,%22ww%22:0}&brightness=100

these is milight group with a set of bulbs

Re: if time set color

Posted: Thursday 05 September 2019 0:29
by waaren
Gianni wrote: Wednesday 04 September 2019 22:43 I got the json and this works when enteren manual but i can not get it work in a script.
I assume you tried it in Lua ? Can you share what you have so far ?

Re: if time set color

Posted: Thursday 05 September 2019 14:06
by Gianni
hey waaren

my fault it's dzvents(can someone move this topic?)

so far i got these (it's a cheap pir 433 that only sent a off command)

Code: Select all

return 
{
    active = true,
    
    on = { devices = { 'Motion_Wc' }},
    
    execute = function(domoticz,sensorwc)
        local lichtliving = domoticz.devices('Lichten_Living')
        if (sensorwc.state == 'Off' and domoticz.time.matchesRule('between sunrise and sunset'))then
            lichtliving.cancelQueuedCommands()
           lichtliving.switchOn().checkFirst()
            domoticz.openURL('http://ip:port/json.htm?type=command&param=setcolbrightnessvalue&idx=93&color={%22m%22:3,%22t%22:0,%22r%22:0,%22g%22:1,%22b%22:255,%22cw%22:0,%22ww%22:0}&brightness=50')
            lichtliving.switchOff().afterSec(60)
            
        else 
          lichtliving.cancelQueuedCommands()
           lichtliving.switchOn().checkFirst()
           domoticz.openURL('http://ip:port/json.htm?type=command&param=setcolbrightnessvalue&idx=93&color={%22m%22:3,%22t%22:0,%22r%22:0,%22g%22:1,%22b%22:255,%22cw%22:0,%22ww%22:0}&brightness=50')
             lichtliving.switchOff().afterSec(60)
            
        end
    end
}

so my problem now
i cannot set time 'between 8.00 and 18.00'
it's only work between sunset and sunrise works.
The the light go on.
But not dim and no color.
then it's go to the url and set the dim and color
but only 3 of the 10 time's its working :-)

the goal is direct set the dim and color at switch on.

Re: if time set color

Posted: Thursday 05 September 2019 18:21
by waaren
Gianni wrote: Thursday 05 September 2019 14:06 my fault it's dzvents(can someone move this topic?)
i cannot set time 'between 8.00 and 18.00'

the goal is direct set the dim and color at switch on.
I moved the topic.
You could try

Code: Select all

domoticz.time.matchesRule('at 08:00-18:00')
Can you please state your domoticz / dzVents version ? It might make a difference forthe best way to deal with the other issue. Thx

Re: if time set color

Posted: Thursday 05 September 2019 20:25
by Gianni
thx for moving the topic

hmmmm is this not a dzvents?

Code: Select all

return 
{
    active = true,
    
    on = { devices = { 'Motion_Wc' }},
    
    execute = function(domoticz,sensorwc)
        local lichtliving = domoticz.devices('Lichten_Living')
        if (sensorwc.state == 'Off' and domoticz.time.matchesRule('between sunrise and sunset'))then
            lichtliving.cancelQueuedCommands()
           lichtliving.switchOn().checkFirst()
            domoticz.openURL('http://ip:port/json.htm?type=command&param=setcolbrightnessvalue&idx=93&color={%22m%22:3,%22t%22:0,%22r%22:0,%22g%22:1,%22b%22:255,%22cw%22:0,%22ww%22:0}&brightness=50')
            lichtliving.switchOff().afterSec(60)
            
        else 
          lichtliving.cancelQueuedCommands()
           lichtliving.switchOn().checkFirst()
           domoticz.openURL('http://ip:port/json.htm?type=command&param=setcolbrightnessvalue&idx=93&color={%22m%22:3,%22t%22:0,%22r%22:0,%22g%22:1,%22b%22:255,%22cw%22:0,%22ww%22:0}&brightness=50')
             lichtliving.switchOff().afterSec(60)
            
        end
    end
}
i try with 'at' instead of between but it's make no different

Re: if time set color

Posted: Thursday 05 September 2019 20:36
by waaren
Gianni wrote: Thursday 05 September 2019 20:25 hmmmm is this not a dzvents?
i try with 'at' instead of between but it's make no different
:o Strange and yes it is dzVents code. Please state the domoticz / dzVents versions you are on. ( [Setup] [About] )

Re: if time set color

Posted: Thursday 05 September 2019 21:19
by Gianni
oeps mis read :-)
my version is dzVents Version: 2.4.19
raspian os version buster

Re: if time set color

Posted: Thursday 05 September 2019 22:56
by waaren
Gianni wrote: Thursday 05 September 2019 21:19 oeps mis read :-)
my version is dzVents Version: 2.4.19
raspian os version buster
Can you try this ?

Code: Select all

return 
{
    active = true,
    
    on = { devices = { 'Motion_Wc' }},
    
    logging = 
    { 
        level = domoticz.LOG_DEBUG, 
        marker  = setColor, 
    },
    
    execute = function(domoticz, sensorwc)
        local lichtliving = domoticz.devices('Lichten_Living')
        
        local colorMode = 3
        local whiteMode = 2

        domoticz.log('Status of Motion WC is ' .. sensorwc.state,domoticz.LOG_DEBUG)
        
        local function setLight(mode)
            domoticz.openURL(
                                'http://192.168.192.59:8084/json.htm?type=command&param=setcolbrightnessvalue&idx=' .. 
                                lichtliving.idx .. 
                                '&color={"m":' .. 
                                mode ..
                                ',"t":0,"r":0,"g":1,"b":255,"cw":0,"ww":0}&brightness=50'
                             )
        end
        
        -- According to your previous post the sensor only sends an 'Off signal we don't have to check state
        lichtliving.cancelQueuedCommands()
        
        if domoticz.time.matchesRule('at 08:00-23:00') then
            lichtliving.setColor(0,1,255, 50, 0, 0, colorMode, 0) -- Version >= 2.4.16 required for setColor command
            -- setLight(colorMode) -- Not used here but avaiable for Version <= 2.4.15
        else 
            lichtliving.setColor(0,1,255, 50, 0, 0, whiteMode, 0)
           -- setLight(whiteMode)
        end
       
        lichtliving.switchOff().afterSec(60)
    end
}

Re: if time set color

Posted: Friday 06 September 2019 9:15
by Gianni
hey waaren

thx but this script is way to far for me ;-)
where did you find al these functions,because in the dzvents wiki i did not found all that.

But now back to the script.

Code: Select all

 2019-09-06 09:05:07.048 (RF_433) Light/Switch (Motion_Wc)
2019-09-06 09:05:07.207 Status: dzVents: Info: Handling events for: "Motion_Wc", value: "Off"
2019-09-06 09:05:07.207 Status: dzVents: Info: ------ Start internal script: Script #2: Device: "Motion_Wc (RF_433)", Index: 108
2019-09-06 09:05:07.208 Status: dzVents: Debug: Processing device-adapter for Lichten_Living: Switch device adapter
2019-09-06 09:05:07.208 Status: dzVents: Debug: Status of Motion WC is Off
2019-09-06 09:05:07.208 Status: dzVents: Error (2.4.19): Method setColor is not available for device "Lichten_Living" (deviceType=Light/Switch, deviceSubType=Switch). If you believe this is not correct, please report.
2019-09-06 09:05:07.208 Status: dzVents: Debug: Constructed timed-command: Off
2019-09-06 09:05:07.209 Status: dzVents: Debug: Constructed timed-command: Off AFTER 60 SECONDS
2019-09-06 09:05:07.209 Status: dzVents: Info: ------ Finished Script #2
so lets explain a little bit how my setup is .
a zwave wall switch with idx 130
These lights are all milights bulbs in four groups on the controller.(wc/living/kookplaats/keuken)

Code: Select all

	
91	Milight_Lampen	1	0	AppLamp All	       Color Switch	 RGBWW	                Off	-	-	
92	Milight_Lampen	1	1	Groep_Wc	               Color Switch	RGBWW	                 Set Level: 100 %	-	-	
93	Milight_Lampen	1	2	Groep_Living	       Color Switch	RGBWW	                 Set Color	-	-	
94	Milight_Lampen	1	3	Groep_Keuken	        Color Switch	RGBWW	                 Set Color	-	-	
95	Milight_Lampen	1	4	Groep_Kookplaats	Color Switch	RGBWW	                 On	-	-	 
96	Milight_Lampen	1	5	AppLamp Bridge	Color Switch	RGBWW	                 Off
grts

Re: if time set color

Posted: Friday 06 September 2019 9:38
by waaren
Gianni wrote: Friday 06 September 2019 9:15 where did you find al these functions,because in the dzvents wiki i did not found all that.
All code in this script is either standard Lua or dzVents code explained in the wiki. If you don't understand part of the code then please ask. I will be happy to clarify.

I don't see Lichten_Living in your overview ?

Can you try with this ?
This is without calling the setColor method but with a direct call the domoticz API.

Code: Select all

return 
{
    active = true,
    
    on = { devices = { 'Motion_Wc' }},
    
    logging = 
    { 
        level = domoticz.LOG_DEBUG, 
        marker  = setColor, 
    },
    
    execute = function(domoticz, sensorwc)
        local lichtliving = domoticz.devices('Lichten_Living')
        
        local colorMode = 3
        local whiteMode = 2

        domoticz.log('Status of Motion WC is ' .. sensorwc.state,domoticz.LOG_DEBUG)
        
        local function setLight(mode)
            domoticz.openURL(
                                'http://192.168.192.59:8084/json.htm?type=command&param=setcolbrightnessvalue&idx=' .. 
                                lichtliving.idx .. 
                                '&color={"m":' .. 
                                mode ..
                                ',"t":0,"r":0,"g":1,"b":255,"cw":0,"ww":0}&brightness=50'
                             )
        end
        
        -- According to your previous post the sensor only sends an 'Off signal we don't have to check state
        lichtliving.cancelQueuedCommands()
        
        if domoticz.time.matchesRule('at 08:00-23:00') then
            -- lichtliving.setColor(0,1,255, 50, 0, 0, colorMode, 0) -- -- Not used here but avaiable for Version >= 2.4.19
            setLight(colorMode) 
        else 
            -- lichtliving.setColor(0,1,255, 50, 0, 0, whiteMode, 0)
           setLight(whiteMode)
        end
       
        lichtliving.switchOff().afterSec(60)
    end
}

Re: if time set color

Posted: Friday 06 September 2019 9:55
by Gianni
lichten_living is the neo wall swicht with idx 130
but the wall switch is never triggered with the script
so the light is not going on

Code: Select all

 2019-09-06 09:50:08.524 Status: dzVents: Write file: /home/gianni/domoticz/scripts/dzVents/generated_scripts/Script #2.lua
2019-09-06 09:50:11.088 Status: dzVents: Info: Handling events for: "Motion_Wc", value: "Off"
2019-09-06 09:50:11.088 Status: dzVents: Info: ------ Start internal script: Script #2: Device: "Motion_Wc (RF_433)", Index: 108
2019-09-06 09:50:11.090 Status: dzVents: Debug: Processing device-adapter for Lichten_Living: Switch device adapter
2019-09-06 09:50:11.090 Status: dzVents: Debug: Status of Motion WC is Off
2019-09-06 09:50:11.090 Status: dzVents: Debug: OpenURL: url = http://10.10.30.3:8085/json.htm?type=command&param=setcolbrightnessvalue&idx=130&color={"m":3,"t":0,"r":0,"g":1,"b":255,"cw":0,"ww":0}&brightness=50
2019-09-06 09:50:11.090 Status: dzVents: Debug: OpenURL: method = GET
2019-09-06 09:50:11.090 Status: dzVents: Debug: OpenURL: post data = nil
2019-09-06 09:50:11.090 Status: dzVents: Debug: OpenURL: headers = nil
2019-09-06 09:50:11.090 Status: dzVents: Debug: OpenURL: callback = nil
2019-09-06 09:50:11.090 Status: dzVents: Debug: Constructed timed-command: Off
2019-09-06 09:50:11.090 Status: dzVents: Debug: Constructed timed-command: Off AFTER 60 SECONDS
2019-09-06 09:50:11.091 Status: dzVents: Info: ------ Finished Script #2
2019-09-06 09:50:11.092 Status: EventSystem: Script event triggered: /home/gianni/domoticz/dzVents/runtime/dzVents.lua
2019-09-06 09:50:11.132 Status: setcolbrightnessvalue: ID: 82, bri: 50, color: '{m: 3, RGB: 0000ff, CWWW: 0000, CT: 0}'

2019-09-06 09:51:11.306 Status: dzVents: Info: Handling events for: "Lichten_Living", value: "Off"
2019-09-06 09:51:11.306 Status: dzVents: Info: ------ Start internal script: Wissel_Living: Device: "Lichten_Living (Controller)", Index: 130
2019-09-06 09:51:11.308 Status: dzVents: Info: ------ Finished Wissel_Living 

Re: if time set color

Posted: Friday 06 September 2019 10:11
by Gianni
update

if i put this code in then the lights go on but stay on the last color/dim

Code: Select all

        lichtliving.cancelQueuedCommands()
                 lichtliving.switchOn()
this is the log

Code: Select all

 2019-09-06 10:08:48.290 Status: dzVents: Debug: Status of Motion WC is Off
2019-09-06 10:08:48.290 Status: dzVents: Debug: Constructed timed-command: On
2019-09-06 10:08:48.291 Status: dzVents: Debug: OpenURL: url = http://10.10.30.3:8085/json.htm?type=command&param=setcolbrightnessvalue&idx=130&color={"m":3,"t":0,"r":0,"g":1,"b":255,"cw":0,"ww":0}&brightness=50
2019-09-06 10:08:48.291 Status: dzVents: Debug: OpenURL: method = GET
2019-09-06 10:08:48.291 Status: dzVents: Debug: OpenURL: post data = nil
2019-09-06 10:08:48.291 Status: dzVents: Debug: OpenURL: headers = nil
2019-09-06 10:08:48.291 Status: dzVents: Debug: OpenURL: callback = nil
2019-09-06 10:08:48.291 Status: dzVents: Debug: Constructed timed-command: Off
2019-09-06 10:08:48.291 Status: dzVents: Debug: Constructed timed-command: Off AFTER 60 SECONDS
2019-09-06 10:08:48.291 Status: dzVents: Info: ------ Finished Script #2
2019-09-06 10:08:48.293 Status: EventSystem: Script event triggered: /home/gianni/domoticz/dzVents/runtime/dzVents.lua
2019-09-06 10:08:48.318 Status: setcolbrightnessvalue: ID: 82, bri: 50, color: '{m: 3, RGB: 0000ff, CWWW: 0000, CT: 0}'
2019-09-06 10:08:48.533 Status: dzVents: Info: Handling events for: "Lichten_Living", value: "On"
2019-09-06 10:08:48.533 Status: dzVents: Info: ------ Start internal script: Wissel_Living: Device: "Lichten_Living (Controller)", Index: 130
2019-09-06 10:08:48.535 Status: dzVents: Info: ------ Finished Wissel_Living


Re: if time set color

Posted: Friday 06 September 2019 15:30
by waaren
Gianni wrote: Friday 06 September 2019 9:55 lichten_living is the neo wall swicht with idx 130
but the wall switch is never triggered with the script
so the light is not going on
OK, my bad. I did not understood that part. I tought lichtliving was the RGBWW device (the bulb). Would it be possible to keep the switch On ?
The commands to the bulb itself can turn on/off the light. Otherwise you will probably have a timing issue (the bulb is not ready yet to receive the setColor commands when that arrives)
If that is not possible the openURL must be send with a delay. ( afterSec(X) )