Update selector switch status with other switch, both ways  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
FunFair
Posts: 52
Joined: Wednesday 04 October 2017 11:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Update selector switch status with other switch, both ways

Post by FunFair »

Hi, I am using a logitech harmony hub which makes multiple switches in Domoticz.
I've made a LUA script that updates a selector switch when I press the remote and domoticz notices that the switch has changed.
And if I press the selector switch, it will send the corresponding switch command to the harmony hub. WIth LUA I did this with the 'changeddevice' and 'otherdevice'

I am trying to update this script to dzVentz, but I'm stuck in a loop. Whenever I press a button on the remote, or on the selector switch, my system will turn off/on/off/on/etc.

This is my script. Can anyone point me to what I am doing wrong?

Code: Select all

return {
    active = true,
	on = {
		devices = {
		    'Harmony Hub',              -- selector switch level names: 'Uit', 'Media', 'TV', 'Spotify', 'Switch', 'Wii'
			'$Harmony_PowerOff',        -- harmony hub switch
			'$Harmony_Mediacenter',     -- harmony hub switch
			'$Harmony_TV',              -- harmony hub switch
			'$Harmony_Spotify',         -- harmony hub switch
			'$Harmony_Switch',          -- harmony hub switch
			'$Harmony_Wii'              -- harmony hub switch
			},
	},

execute = function(domoticz, devices)
    
    if (domoticz.devices('Harmony Hub').state == 'Uit') and 
        (domoticz.devices('$Harmony_PowerOff').state == 'Off')
    
        then domoticz.devices('$Harmony_PowerOff').switchOn().checkFirst()

    elseif (domoticz.devices('$Harmony_PowerOff').state == 'On') and 
        (domoticz.devices('Harmony Hub').state ~= 'Uit')
        
        then domoticz.devices('Harmony Hub').switchSelector('Uit')
    end    

    if (domoticz.devices('Harmony Hub').state == 'Media') and 
        (domoticz.devices('$Harmony_Mediacenter').state == 'Off')
    
        then domoticz.devices('$Harmony_Mediacenter').switchOn().checkFirst()

    elseif (domoticz.devices('$Harmony_Mediacenter').state == 'On') and 
        (domoticz.devices('Harmony Hub').state ~= 'Media')
        
        then domoticz.devices('Harmony Hub').switchSelector('Media')
    end    

 end
}
FunFair
Posts: 52
Joined: Wednesday 04 October 2017 11:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Update selector switch status with other switch, both ways

Post by FunFair »

This is my LUA script that works fine.

Code: Select all

commandArray = {}

--Uitschakelen
if (devicechanged['$Harmony_PowerOff'] == "On") and (otherdevices['Harmony Hub'] ~= "Uit") then
    commandArray['Harmony Hub'] = 'Set Level: 0'
elseif (devicechanged['$Ping_Harmony_Hub'] == "On") and (otherdevices['$Harmony_PowerOff'] == "On") and (otherdevices['Harmony Hub'] ~= "Uit") then
    commandArray['Harmony Hub'] = 'Set Level: 0'
elseif (devicechanged['Harmony Hub'] == "Uit") and (otherdevices['$Harmony_PowerOff'] ~= "On") then
    commandArray['$Harmony_PowerOff'] = 'On'

--Mediacenter
elseif (devicechanged['$Harmony_Mediacenter'] == "On") and (otherdevices['Harmony Hub'] ~= "Media") then
    commandArray['Harmony Hub'] = 'Set Level: 10'
elseif (devicechanged['$Ping_Harmony_Hub'] == "On") and (otherdevices['$Harmony_Mediacenter'] == "On") and (otherdevices['Harmony Hub'] ~= "Media") then
    commandArray['Harmony Hub'] = 'Set Level: 10'
elseif (devicechanged['Harmony Hub'] == "Media") and (otherdevices['$Harmony_Mediacenter'] ~= "On") then
    commandArray['$Harmony_Mediacenter'] = 'On'

--TV Kijken
elseif (devicechanged['$Harmony_TV'] == "On") and (otherdevices['Harmony Hub'] ~= "TV") then
    commandArray['Harmony Hub'] = 'Set Level: 20'
elseif (devicechanged['$Ping_Harmony_Hub'] == "On") and (otherdevices['$Harmony_TV'] == "On") and (otherdevices['Harmony Hub'] ~= "TV") then
    commandArray['Harmony Hub'] = 'Set Level: 20'
elseif (devicechanged['Harmony Hub'] == "TV") and (otherdevices['$Harmony_TV'] ~= "On") then
    commandArray['$Harmony_TV'] = 'On'

--Spotify
elseif (devicechanged['$Harmony_Spotify'] == "On") and (otherdevices['Harmony Hub'] ~= "Spotify") then
    commandArray['Harmony Hub'] = 'Set Level: 30'
elseif (devicechanged['$Ping_Harmony_Hub'] == "On") and (otherdevices['$Harmony_Spotify'] == "On") and (otherdevices['Harmony Hub'] ~= "Spotify") then
    commandArray['Harmony Hub'] = 'Set Level: 30'
elseif (devicechanged['Harmony Hub'] == "Spotify") and (otherdevices['$Harmony_Spotify'] ~= "On") then
    commandArray['$Harmony_Spotify'] = 'On'

--Switch
elseif (devicechanged['$Harmony_Switch'] == "On") and (otherdevices['Harmony Hub'] ~= "Switch") then
    commandArray['Harmony Hub'] = 'Set Level: 40'
elseif (devicechanged['$Ping_Harmony_Hub'] == "On") and (otherdevices['$Harmony_Switch'] == "On") and (otherdevices['Harmony Hub'] ~= "Switch") then
    commandArray['Harmony Hub'] = 'Set Level: 40'
elseif (devicechanged['Harmony Hub'] == "Switch") and (otherdevices['$Harmony_Switch'] ~= "On") then
    commandArray['$Harmony_Switch'] = 'On'

--Wii
elseif (devicechanged['$Harmony_Wii'] == "On") and (otherdevices['Harmony Hub'] ~= "Wii") then
    commandArray['Harmony Hub'] = 'Set Level: 50'
elseif (devicechanged['$Ping_Harmony_Hub'] == "On") and (otherdevices['$Harmony_Wii'] == "On") and (otherdevices['Harmony Hub'] ~= "Wii") then
    commandArray['Harmony Hub'] = 'Set Level: 50'
elseif (devicechanged['Harmony Hub'] == "Wii") and (otherdevices['$Harmony_Wii'] ~= "On") then
    commandArray['$Harmony_Wii'] = 'On'

end
return commandArray
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Update selector switch status with other switch, both ways

Post by waaren »

FunFair wrote: Tuesday 09 July 2019 21:13 I am trying to update this script to dzVentz, but I'm stuck in a loop. Whenever I press a button on the remote, or on the selector switch, my system will turn off/on/off/on/etc.
I guess you get into a loop because the script activates a devices that in it's turn trigger the script etc. Should be visible in the log. You can prevent this by using the method silent()

Can you try this ?

Code: Select all


return {
    active = true,
	on = {
		devices = {
		    'Harmony Hub',              -- selector switch level names: 'Uit', 'Media', 'TV', 'Spotify', 'Switch', 'Wii'
			'$Harmony_PowerOff',        -- harmony hub switch
			'$Harmony_Mediacenter',     -- harmony hub switch
			'$Harmony_TV',              -- harmony hub switch
			'$Harmony_Spotify',         -- harmony hub switch
			'$Harmony_Switch',          -- harmony hub switch
			'$Harmony_Wii'              -- harmony hub switch
			},
	},
execute = function( domoticz )
    local hub = domoticz.devices('Harmony Hub')
    local powerOff = domoticz.devices('$Harmony_PowerOff')
    local mediaCenter = domoticz.devices('$Harmony_Mediacenter')
    
    if hub.state == 'Uit' then 
        powerOff.switchOn().checkFirst().silent()
    elseif powerOff.active then 
        hub.switchSelector('Uit').silent()
    elseif hub.state == 'Media' then 
        mediaCenter.switchOn().checkFirst().silent()
    elseif mediaCenter.active then
        hub.switchSelector('Media').silent()
    end

 end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
FunFair
Posts: 52
Joined: Wednesday 04 October 2017 11:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Update selector switch status with other switch, both ways

Post by FunFair »

Thanks. I tried it out. It does not keep switching on/off/on/etc. anymore, but now just keeps shutting off lol.

This is the log after pressing the remote. Same happens when I press the selector switch.

Code: Select all

2019-07-11 09:11:16.025 Status: dzVents: Info: Handling events for: "$Harmony_PowerOff", value: "Off"
2019-07-11 09:11:16.026 Status: dzVents: Info: ------ Start internal script: HamonyHub2_dzVents: Device: "$Harmony_PowerOff (Logitech Harmony Hub)", Index: 421
2019-07-11 09:11:16.028 Status: dzVents: Info: ------ Finished HamonyHub2_dzVents
2019-07-11 09:11:16.317 Status: dzVents: Info: Handling events for: "$Harmony_Mediacenter", value: "On"
2019-07-11 09:11:16.318 Status: dzVents: Info: ------ Start internal script: HamonyHub2_dzVents: Device: "$Harmony_Mediacenter (Logitech Harmony Hub)", Index: 425
2019-07-11 09:11:16.320 Status: dzVents: Info: ------ Finished HamonyHub2_dzVents
2019-07-11 09:11:16.641 Status: dzVents: Info: Handling events for: "Harmony Hub", value: "Media"
2019-07-11 09:11:16.641 Status: dzVents: Info: ------ Start internal script: HamonyHub2_dzVents: Device: "Harmony Hub (Dummy)", Index: 346
2019-07-11 09:11:16.643 Status: dzVents: Info: ------ Finished HamonyHub2_dzVents
2019-07-11 09:11:16.811 Status: Harmony Hub: Changing activity 
 2019-07-11 09:11:20.812 Status: Harmony Hub: Finished changing activity
2019-07-11 09:11:20.941 Status: dzVents: Info: Handling events for: "$Harmony_Mediacenter", value: "Off"
2019-07-11 09:11:20.942 Status: dzVents: Info: ------ Start internal script: HamonyHub2_dzVents: Device: "$Harmony_Mediacenter (Logitech Harmony Hub)", Index: 425
2019-07-11 09:11:20.945 Status: dzVents: Info: ------ Finished HamonyHub2_dzVents 
FunFair
Posts: 52
Joined: Wednesday 04 October 2017 11:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Update selector switch status with other switch, both ways

Post by FunFair »

I think it has something to do with the harmony hub switch not updating fast enough so the script retriggers.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Update selector switch status with other switch, both ways

Post by waaren »

FunFair wrote: Thursday 11 July 2019 9:14 Thanks. I tried it out. It does not keep switching on/off/on/etc. anymore, but now just keeps shutting off lol.
Added some log statements to understand what's happening. Can please try again ?

Code: Select all

return 
{
    active = true,
    on = 
    {
        devices = 
        {
            'Harmony Hub',              -- selector switch level names: 'Uit', 'Media', 'TV', 'Spotify', 'Switch', 'Wii'
            '$Harmony_PowerOff',        -- harmony hub switch
            '$Harmony_Mediacenter',     -- harmony hub switch
            '$Harmony_TV',              -- harmony hub switch
            '$Harmony_Spotify',         -- harmony hub switch
            '$Harmony_Switch',          -- harmony hub switch
            '$Harmony_Wii',             -- harmony hub switch
        },
    },
    
    logging = 
    { 
        level = domoticz.LOG_DEBUG, 
        marker = "Harmony hub",
    },

execute = function( dz )
    local hub = dz.devices('Harmony Hub')
    local powerOff = dz.devices('$Harmony_PowerOff')
    local mediaCenter = dz.devices('$Harmony_Mediacenter')
    
    dz.log(dz.settings.dzVentsVersion,dz.LOG_DEBUG)
    dz.log(hub.levelNames,dz.LOG_DEBUG)
    dz.log(hub.levelActions,dz.LOG_DEBUG)
    
    if hub.levelName == 'Uit' then 
        powerOff.switchOn().silent()
        dz.log('powerOff ==>> On',dz.LOG_DEBUG)
    elseif powerOff.active then 
        hub.switchSelector('Uit').silent()
        dz.log('hub ==>> Uit',dz.LOG_DEBUG)
    elseif hub.levelName == 'Media' then 
        mediaCenter.switchOn().silent()
        dz.log('mediaCenter ==>> On',dz.LOG_DEBUG)
    elseif mediaCenter.active then
        hub.switchSelector('Media').silent()
        dz.log('hub ==>> Media',dz.LOG_DEBUG)
    end

 end
}


Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
FunFair
Posts: 52
Joined: Wednesday 04 October 2017 11:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Update selector switch status with other switch, both ways

Post by FunFair »

The result:

Code: Select all

 2019-07-11 15:45:09.684 (Logitech Harmony Hub) Lighting 2 ($Harmony_PowerOff)
2019-07-11 15:45:09.165 Status: Harmony Hub: Finished changing activity
2019-07-11 15:45:09.325 Status: dzVents: Info: Handling events for: "$Harmony_PowerOff", value: "Off"
2019-07-11 15:45:09.326 Status: dzVents: Info: Harmony hub: ------ Start internal script: HarmonyHub_test: Device: "$Harmony_PowerOff (Logitech Harmony Hub)", Index: 421
2019-07-11 15:45:09.328 Status: dzVents: Debug: Harmony hub: Processing device-adapter for Harmony Hub: Switch device adapter
2019-07-11 15:45:09.330 Status: dzVents: Debug: Harmony hub: Processing device-adapter for $Harmony_Mediacenter: Switch device adapter
2019-07-11 15:45:09.330 Status: dzVents: Debug: Harmony hub: 2.4.25
2019-07-11 15:45:09.330 Status: dzVents: Debug: Harmony hub: {"Uit", "Media", "TV", "Spotify", "Switch", "Wii"}
2019-07-11 15:45:09.330 Status: dzVents: Debug: Harmony hub: |||||
2019-07-11 15:45:09.330 Status: dzVents: Debug: Harmony hub: Constructed timed-command: On
2019-07-11 15:45:09.331 Status: dzVents: Debug: Harmony hub: Constructed timed-command: On NOTRIGGER
2019-07-11 15:45:09.331 Status: dzVents: Debug: Harmony hub: powerOff ==>> On
2019-07-11 15:45:09.331 Status: dzVents: Info: Harmony hub: ------ Finished HarmonyHub_test
2019-07-11 15:45:09.633 Status: dzVents: Info: Handling events for: "$Harmony_Mediacenter", value: "On"
2019-07-11 15:45:09.633 Status: dzVents: Info: Harmony hub: ------ Start internal script: HarmonyHub_test: Device: "$Harmony_Mediacenter (Logitech Harmony Hub)", Index: 425
2019-07-11 15:45:09.634 Status: dzVents: Debug: Harmony hub: Processing device-adapter for Harmony Hub: Switch device adapter
2019-07-11 15:45:09.635 Status: dzVents: Debug: Harmony hub: Processing device-adapter for $Harmony_PowerOff: Switch device adapter
2019-07-11 15:45:09.635 Status: dzVents: Debug: Harmony hub: 2.4.25
2019-07-11 15:45:09.635 Status: dzVents: Debug: Harmony hub: {"Uit", "Media", "TV", "Spotify", "Switch", "Wii"}
2019-07-11 15:45:09.635 Status: dzVents: Debug: Harmony hub: |||||
2019-07-11 15:45:09.636 Status: dzVents: Debug: Harmony hub: Constructed timed-command: On
2019-07-11 15:45:09.636 Status: dzVents: Debug: Harmony hub: Constructed timed-command: On NOTRIGGER
2019-07-11 15:45:09.636 Status: dzVents: Debug: Harmony hub: powerOff ==>> On
2019-07-11 15:45:09.636 Status: dzVents: Info: Harmony hub: ------ Finished HarmonyHub_test
2019-07-11 15:45:10.169 Status: Harmony Hub: Changing activity
2019-07-11 15:45:15.181 (Logitech Harmony Hub) Lighting 2 ($Harmony_Mediacenter)
2019-07-11 15:45:15.318 (Logitech Harmony Hub) Lighting 2 ($Harmony_PowerOff)
2019-07-11 15:45:15.172 Status: Harmony Hub: Finished changing activity
2019-07-11 15:45:15.301 Status: dzVents: Info: Handling events for: "$Harmony_Mediacenter", value: "Off"
2019-07-11 15:45:15.301 Status: dzVents: Info: Harmony hub: ------ Start internal script: HarmonyHub_test: Device: "$Harmony_Mediacenter (Logitech Harmony Hub)", Index: 425
2019-07-11 15:45:15.302 Status: dzVents: Debug: Harmony hub: Processing device-adapter for Harmony Hub: Switch device adapter
2019-07-11 15:45:15.303 Status: dzVents: Debug: Harmony hub: Processing device-adapter for $Harmony_PowerOff: Switch device adapter
2019-07-11 15:45:15.303 Status: dzVents: Debug: Harmony hub: 2.4.25
2019-07-11 15:45:15.304 Status: dzVents: Debug: Harmony hub: {"Uit", "Media", "TV", "Spotify", "Switch", "Wii"}
2019-07-11 15:45:15.304 Status: dzVents: Debug: Harmony hub: |||||
2019-07-11 15:45:15.304 Status: dzVents: Debug: Harmony hub: Constructed timed-command: On
2019-07-11 15:45:15.304 Status: dzVents: Debug: Harmony hub: Constructed timed-command: On NOTRIGGER
2019-07-11 15:45:15.304 Status: dzVents: Debug: Harmony hub: powerOff ==>> On
2019-07-11 15:45:15.304 Status: dzVents: Info: Harmony hub: ------ Finished HarmonyHub_tests
It doesn't really seem to reach the switch to Media command. The selector switch does not show it's been triggered in it's log at all.
I'm thinking the script needs a 'changedByDomoticz' and a 'changedByHub' set/reset mecanism or something.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Update selector switch status with other switch, both ways

Post by waaren »

FunFair wrote: Thursday 11 July 2019 15:47 It doesn't really seem to reach the switch to Media command. The selector switch does not show it's been triggered in it's log at all.
I'm thinking the script needs a 'changedByDomoticz' and a 'changedByHub' set/reset mecanism or something.
Guess I overlooked something but I am not sure what yet.
I now re-added a check on states.

Code: Select all

return 
{
    active = true,
    on = 
    {
        devices = 
        {
            'Harmony Hub',              -- selector switch level names: 'Uit', 'Media', 'TV', 'Spotify', 'Switch', 'Wii'
            '$Harmony_PowerOff',        -- harmony hub switch
            '$Harmony_Mediacenter',     -- harmony hub switch
            '$Harmony_TV',              -- harmony hub switch
            '$Harmony_Spotify',         -- harmony hub switch
            '$Harmony_Switch',          -- harmony hub switch
            '$Harmony_Wii',             -- harmony hub switch
        },
    },
    
    logging = 
    { 
        level = domoticz.LOG_DEBUG, 
        marker = "Twilight",
    },

execute = function( dz )
    local hub = dz.devices('Harmony Hub')
    local powerOff = dz.devices('$Harmony_PowerOff')
    local mediaCenter = dz.devices('$Harmony_Mediacenter')
        
    if hub.levelName == 'Uit' and powerOff.state == "Off" then 
        powerOff.switchOn().silent()
        dz.log('powerOff ==>> On',dz.LOG_DEBUG)
    elseif powerOff.active then 
        hub.switchSelector('Uit').silent()
        dz.log('hub ==>> Uit',dz.LOG_DEBUG)
    elseif hub.levelName == 'Media' and mediaCenter.state == "Off" then 
        mediaCenter.switchOn().silent()
        dz.log('mediaCenter ==>> On',dz.LOG_DEBUG)
    elseif mediaCenter.active then
        hub.switchSelector('Media').silent()
        dz.log('hub ==>> Media',dz.LOG_DEBUG)
    end

 end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
FunFair
Posts: 52
Joined: Wednesday 04 October 2017 11:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Update selector switch status with other switch, both ways

Post by FunFair »

Still no succes...
I don't understand why it is switching to 'uit' even though it should go to 'media'.
It's like the feedback coming from the harmony hub is too slow and therefore the script is still seeing the status 'uit'.

Code: Select all

2019-07-11 18:20:27.104 Status: Harmony Hub: Changing activity
2019-07-11 18:20:44.109 Status: Harmony Hub: Finished changing activity
2019-07-11 18:20:44.315 Status: dzVents: Info: Handling events for: "$Harmony_PowerOff", value: "Off"
2019-07-11 18:20:44.316 Status: dzVents: Info: Twilight: ------ Start internal script: HarmonyHub_test: Device: "$Harmony_PowerOff (Logitech Harmony Hub)", Index: 421
2019-07-11 18:20:44.317 Status: dzVents: Debug: Twilight: Processing device-adapter for Harmony Hub: Switch device adapter
2019-07-11 18:20:44.318 Status: dzVents: Debug: Twilight: Processing device-adapter for $Harmony_Mediacenter: Switch device adapter
2019-07-11 18:20:44.318 Status: dzVents: Debug: Twilight: Constructed timed-command: On
2019-07-11 18:20:44.318 Status: dzVents: Debug: Twilight: Constructed timed-command: On NOTRIGGER
2019-07-11 18:20:44.318 Status: dzVents: Debug: Twilight: powerOff ==>> On
2019-07-11 18:20:44.318 Status: dzVents: Info: Twilight: ------ Finished HarmonyHub_test

2019-07-11 18:20:44.625 Status: dzVents: Info: Handling events for: "$Harmony_Mediacenter", value: "On"
2019-07-11 18:20:44.625 Status: dzVents: Info: Twilight: ------ Start internal script: HarmonyHub_test: Device: "$Harmony_Mediacenter (Logitech Harmony Hub)", Index: 425
2019-07-11 18:20:44.627 Status: dzVents: Debug: Twilight: Processing device-adapter for Harmony Hub: Switch device adapter
2019-07-11 18:20:44.628 Status: dzVents: Debug: Twilight: Processing device-adapter for $Harmony_PowerOff: Switch device adapter
2019-07-11 18:20:44.628 Status: dzVents: Debug: Twilight: Constructed timed-command: Set Level 0
2019-07-11 18:20:44.628 Status: dzVents: Debug: Twilight: Constructed timed-command: Set Level 0 NOTRIGGER
2019-07-11 18:20:44.628 Status: dzVents: Debug: Twilight: hub ==>> Uit
2019-07-11 18:20:44.628 Status: dzVents: Info: Twilight: ------ Finished HarmonyHub_test

2019-07-11 18:20:45.113 Status: Harmony Hub: Changing activity
2019-07-11 18:20:49.114 Status: Harmony Hub: Finished changing activity
2019-07-11 18:20:49.356 Status: dzVents: Info: Handling events for: "$Harmony_Mediacenter", value: "Off"
2019-07-11 18:20:49.356 Status: dzVents: Info: Twilight: ------ Start internal script: HarmonyHub_test: Device: "$Harmony_Mediacenter (Logitech Harmony Hub)", Index: 425
2019-07-11 18:20:49.358 Status: dzVents: Debug: Twilight: Processing device-adapter for Harmony Hub: Switch device adapter
2019-07-11 18:20:49.361 Status: dzVents: Debug: Twilight: Processing device-adapter for $Harmony_PowerOff: Switch device adapter
2019-07-11 18:20:49.361 Status: dzVents: Debug: Twilight: Constructed timed-command: Set Level 0
2019-07-11 18:20:49.362 Status: dzVents: Debug: Twilight: Constructed timed-command: Set Level 0 NOTRIGGER
2019-07-11 18:20:49.362 Status: dzVents: Debug: Twilight: hub ==>> Uit
2019-07-11 18:20:49.362 Status: dzVents: Info: Twilight: ------ Finished HarmonyHub_test 
FunFair
Posts: 52
Joined: Wednesday 04 October 2017 11:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Update selector switch status with other switch, both ways  [Solved]

Post by FunFair »

Succes!!!! had to add an command .changed to check if the device was the trigger or not!
Now I have to clean up and add the other switches :)
Thanks for thinking with me!

Code: Select all

return 
{
    active = true,
    on = 
    {
        devices = 
        {
            'Harmony Hub',              -- selector switch level names: 'Uit', 'Media', 'TV', 'Spotify', 'Switch', 'Wii'
            '$Harmony_PowerOff',        -- harmony hub switch
            '$Harmony_Mediacenter',     -- harmony hub switch
            '$Harmony_TV',              -- harmony hub switch
            '$Harmony_Spotify',         -- harmony hub switch
            '$Harmony_Switch',          -- harmony hub switch
            '$Harmony_Wii',             -- harmony hub switch
        },
    },
    
    logging = 
    { 
        level = domoticz.LOG_DEBUG, 
        marker = "Twilight",
    },

execute = function( dz )
    local hub = dz.devices('Harmony Hub')
    local powerOff = dz.devices('$Harmony_PowerOff')
    local mediaCenter = dz.devices('$Harmony_Mediacenter')
        
    if hub.changed and hub.levelName == 'Uit' and powerOff.state == 'Off' then 
        powerOff.switchOn().silent()
        dz.log('powerOff ==>> On',dz.LOG_DEBUG)
    elseif powerOff.changed and powerOff.active then 
        hub.switchSelector('Uit').silent()
        dz.log('hub ==>> Uit',dz.LOG_DEBUG)
    elseif hub.changed and hub.levelName == 'Media' and mediaCenter.state == 'Off' then 
        mediaCenter.switchOn().silent()
        dz.log('mediaCenter ==>> On',dz.LOG_DEBUG)
    elseif mediaCenter.changed and mediaCenter.active then
        hub.switchSelector('Media').silent()
        dz.log('hub ==>> Media',dz.LOG_DEBUG)
    end

 end
}
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest