sub slave devices

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

sub slave devices

Post by snellejellep »

I have a question about sub slave devices, the manual said that it was the most difficult and complicated part and that seems to be true so i hope someone over here can help me.

What i want to acomplish:
i have two led strips, for now call them LED_strip1 and LED_strip2. If i turn LED_strip1 on i want LED_strip2 to turn on with it but when i turn on LED_strip2 i do not want LED_strip1 to turn on.
That i accomplished with the sub slave devices and it works fine but there is one problem, If i dim or change the color of LED_strip1 LED_strip2 does not dim or change color als LED_strip1 does, the sub slave device connection does seem to only affect the on/off state. is this normal behavior or am i configuring something wrong?

i hope someone can help me and possibly others.
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: sub slave devices

Post by snellejellep »

no one an idea?
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
devros
Posts: 183
Joined: Saturday 29 October 2016 20:55
Target OS: -
Domoticz version:
Contact:

Re: sub slave devices

Post by devros »

afaik is usable only for on/off state...
you will have to use some sort of script (dzvents)
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: sub slave devices

Post by snellejellep »

devros wrote: Friday 25 May 2018 14:04 afaik is usable only for on/off state...
you will have to use some sort of script (dzvents)
too bad i am not really good at that sort of thing, blockly is what i use and some example lua scripts.
i can read most things in scripts but writing them is a whole other level, respect to those who can!
but if any one has some spare time, feel free to suggest something because i have no idea how i can accomplish that.
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: sub slave devices

Post by waaren »

snellejellep wrote: Friday 25 May 2018 14:11 ....
but if any one has some spare time, feel free to suggest something because i have no idea how i can accomplish that.
This might help:

Code: Select all

--[[ LEDSlaveDemo.lua (tested and working on dzVents 2.4.5)
 ]]--
 
return {
    on = { devices = { "LED_strip1" } },
    
    logging =   {       level   =   domoticz.LOG_INFO,                  -- switch to LOG_DEBUG when needed                                   
                        marker  =   "LEDSlaveDemo" },                                           

    
    execute = function(dz, trigger)
        local slave = dz.devices("LED_strip2")
        dz.log(trigger.name .. " state: " .. trigger.state ..", dimlevel: " .. trigger.level .. "%"  ,dz.LOG_DEBUG)
         
        if trigger.state == "On" then 
            slave.switchOn().checkFirst()                 -- remove the checkFirst() if you also control the on/off state of this dimmer outside domoticz
            slave.dimTo(trigger.level)
        else
            slave.switchOff().checkFirst()                -- remove the checkFirst() if you also control the on/off state of this dimmer outside domoticz
        end
        
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: sub slave devices

Post by snellejellep »

waaren wrote: Saturday 26 May 2018 17:38
snellejellep wrote: Friday 25 May 2018 14:11 ....
but if any one has some spare time, feel free to suggest something because i have no idea how i can accomplish that.
This might help:

Code: Select all

--[[ LEDSlaveDemo.lua (tested and working on dzVents 2.4.5)
 ]]--
 
return {
    on = { devices = { "LED_strip1" } },
    
    logging =   {       level   =   domoticz.LOG_INFO,                  -- switch to LOG_DEBUG when needed                                   
                        marker  =   "LEDSlaveDemo" },                                           

    
    execute = function(dz, trigger)
        local slave = dz.devices("LED_strip2")
        dz.log(trigger.name .. " state: " .. trigger.state ..", dimlevel: " .. trigger.level .. "%"  ,dz.LOG_DEBUG)
         
        if trigger.state == "On" then 
            slave.switchOn().checkFirst()                 -- remove the checkFirst() if you also control the on/off state of this dimmer outside domoticz
            slave.dimTo(trigger.level)
        else
            slave.switchOff().checkFirst()                -- remove the checkFirst() if you also control the on/off state of this dimmer outside domoticz
        end
        
    end
}
wow thanks, i will check that out! and thanks for the comments in the code, maby i can pick up something from that and try it out myself. again, massive thanks!
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: sub slave devices

Post by waaren »

snellejellep wrote: Thursday 24 May 2018 15:30 If i dim or change the color of LED_strip1 LED_strip2 does not dim or change color als LED_strip1 does, the sub slave device connection does seem to only affect the on/off state. is this normal behavior or am i configuring something wrong?
On / Off and dimLevel is now handled in the script but Color and brightness is a small challenge. What type / subtype are your LED strips ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: sub slave devices

Post by snellejellep »

waaren wrote: Monday 28 May 2018 10:17 On / Off and dimLevel is now handled in the script but Color and brightness is a small challenge. What type / subtype are your LED strips ?
i noticed that when i dim it turns off the "slave" and when i dim again it turns back on, i dont know if that is normal or not but i wanted to mention that.

for what led strips i use: the so called master is an philips hue led strip and the slave a yeelight led strip.

if you need more information/tests etc. feel free to ask
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: sub slave devices

Post by waaren »

Thx for your reply.

I was referring to the type / subtype as displayed in the devices tab.
devices.PNG
devices.PNG (156.27 KiB) Viewed 4935 times
When I have that info I will play a little bit further with the script and also try to copy the color and brightness Will then also look into your remark that the slave switches off when you dim the master the first time.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: sub slave devices

Post by snellejellep »

well i do not have dzvents hardware but these are my devices
Image
Image

i hope this helps you?
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: sub slave devices

Post by waaren »

@snellejellep,

:) DzVents weather is just a name of one of my dummy hardware. In use only to define virtual devices.

and yes this is the information I need to continue my little script puzzle. Will get back to you once I have something and tested the different scenarios.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: sub slave devices

Post by snellejellep »

@waaren,

i tried the script, it does work fine when i use the switches in domoticz but when i use my hue dimmer switch that i have on the wall it does not seem to react. or is it because i first saved the script, tried it and then realized that there were comments that said i had to remove the checkfirst, which i did afterwards? because i saw in the log that it created a lua script? so maby that is not updated when i update in domoticz? i cant seem to find it in the logs
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: sub slave devices

Post by waaren »

snellejellep wrote: Monday 28 May 2018 19:19 @waaren,

i tried the script, it does work fine when i use the switches in domoticz but when i use my hue dimmer switch that i have on the wall it does not seem to react. or is it because i first saved the script, tried it and then realized that there were comments that said i had to remove the checkfirst, which i did afterwards? because i saw in the log that it created a lua script? so maby that is not updated when i update in domoticz? i cant seem to find it in the logs
Please try this updated script. Much obliged if you could report your findings. Master - Slave setup with colors is not completely straight forward as the time the script is triggered the color value is not yet landed in dzVents. So script must be forced to execute a second time.
To do this a couple of vars must be stored in the data section.
I tested with a HUE bulb and a Yeelight bulb and color is following now but still look a bit different.

Code: Select all

--[[ LEDSlaveDemo.lua (tested and working on dzVents 2.4.6) but probably also working on earlier versions
  ]]--
 
return {
    on = { devices = {"LED_strip1" } },
    
    logging =   {       level   =   domoticz.LOG_DEBUG,                  -- switch to LOG_INFO when results are OK 
                        marker  =   "LEDSlaveDemo" },                                           

    data    =   {      setColor         = { initial = true },           -- This is necessary because color does not follow in the first pass
                       dimLevel         = { initial = 50   }, 
                       color            = { initial = {}   }}, 
                       
    execute = function(dz, trigger)
        local slave   = dz.devices("LED_strip2")
        
        dz.log("Master ( name / state / level / color )  ( " .. 
                        trigger.name .. " / " .. 
                        trigger.state .. " / " .. 
                        trigger.level .. " / " .. 
                        trigger.color .. " )",dz.LOG_DEBUG)
        
        colorTable = dz.utils.fromJSON(trigger.color)                       -- convert color (a json string) to a Lua table
        
        if trigger.state ~= "Off" and trigger.level > 0 then                -- State can be "On", "Off" or "set Color" 
            dz.data.dimLevel =  trigger.level
            dz.data.color    =  trigger.color
            slave.setRGB(  colorTable.r, colorTable.g, colorTable.b )  
            slave.dimTo(tonumber(dz.data.dimLevel))
            if dz.data.setColor then                                        -- We need to trigger the script another time as the color 
                dz.data.dimLevel =  trigger.level                           -- does not follow the first pass. Does not seem timing but looks like    
                trigger.dimTo(dz.data.dimLevel)                             -- dzVents is not yet updated with right color values from master
                dz.data.setColor = false                                  
            else
                dz.data.setColor = true
            end 
        else
            slave.switchOff()
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: sub slave devices

Post by snellejellep »

it now works! wow! thanks! only one small thing is that it does not seem to mirror te color to the second strip? or maby that is because the hue strip is an rgbw strip with two white tone leds in addition to the rgb ones and the yeelight only has the rgb ones. but sill, massive thanks!
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: sub slave devices

Post by waaren »

snellejellep wrote: Tuesday 29 May 2018 8:07 it now works! wow! thanks! only one small thing is that it does not seem to mirror te color to the second strip? or maby that is because the hue strip is an rgbw strip with two white tone leds in addition to the rgb ones and the yeelight only has the rgb ones. but sill, massive thanks!
[EDIT]
Error was "Error opening url: http://127.0.0.1:8080/json.htm?param=se ... hite=false"
this means dzVents has no access to the domoticz API via a HTTP json call

Solution: SETUP -> SETTINGS -> SYSTEM -> SYSTEM SETUP
[ LOCAL NETWORKS (NO USERNAME / PASSWORD ]

enter (at least) 127.0.0.*

after [APLLY SETTINGS] dzVents will be able to send / receive information to/ from domoticz using HTTP json calls
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
schumi2004
Posts: 24
Joined: Tuesday 17 October 2017 19:38
Target OS: NAS (Synology & others)
Domoticz version: 4.10603
Contact:

Re: sub slave devices

Post by schumi2004 »

@waaren
Thanks for your example, just the thing i was looking for but could you maybe explain how to use it?
If i understand it correctly i should make Led_strip2 a slave of Led_strip1, then i add your script as a Lua Device (or All) script or should i add it as a dzVents script and again Device?

Thanks in advance.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: sub slave devices

Post by waaren »

schumi2004 wrote: Thursday 07 March 2019 19:07If i understand it correctly i should make Led_strip2 a slave of Led_strip1, then i add your script as a Lua Device (or All) script or should i add it as a dzVents script and again Device?
Using this script Led_strip2 will follow state and color of Led_strip1. No need to set anything else as long as the device types / subtypes are the same.
How you add the script using the event editor does not change the behavior of it. That choice does only change the template used in the editor but you should overwrite it completely with this script.
Hope this clarifies.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
schumi2004
Posts: 24
Joined: Tuesday 17 October 2017 19:38
Target OS: NAS (Synology & others)
Domoticz version: 4.10603
Contact:

Re: sub slave devices

Post by schumi2004 »

Hi waaren,

Thanks for the feedback.
Eventually i got it running without errors but for some reason the Strip2 did not follow Strip1 although devices are the same.
Maybe it's because of a misconfiguration on my side but i will debug that later tomorrow.
schumi2004
Posts: 24
Joined: Tuesday 17 October 2017 19:38
Target OS: NAS (Synology & others)
Domoticz version: 4.10603
Contact:

Re: sub slave devices

Post by schumi2004 »

Is it possible to use this also for Ikea Tradfri Bulb's ?

I tried but it returned an error.

2019-04-25 19:56:05.357 Status: dzVents: Error (2.4.18): Ikea GU10 Comp Nis Slave: An error occured when calling event handler Computer NIS Slave
2019-04-25 19:56:05.357 Status: dzVents: Error (2.4.18): Ikea GU10 Comp Nis Slave: ...scripts/dzVents/generated_scripts/Computer NIS Slave.lua:21: attempt to concatenate field 'color' (a nil value)

Is that because Tradfri lights don't actual have a color option?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: sub slave devices

Post by waaren »

schumi2004 wrote: Thursday 25 April 2019 19:59 Is it possible to use this also for Ikea Tradfri Bulb's ?
I am afraid not. I don't own Ikea bulbs but understand they are managed by a plugin.
Is that because Tradfri lights don't actual have a color option?
Yes. The script can only work if both source use the color field. Maybe you can ask the developer of the plugin if this master / slave function can be implemented ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest