Stuck with a script

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

Moderator: leecollings

Post Reply
HvdW
Posts: 615
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Stuck with a script

Post by HvdW »

Hi,
I had a script running for years without any problem.
Then there was this lan problem and the shelly device didn't react.
I tried to solve it by adapting the script and that made things even worse.

Here's the situation.
I have some old Ikea plugs wich are switched with rfxtfx (433 mHz)
When 'piano aan' is switched I want to switch selly21 device on as well.
When 'piano uit' is switched I want to switch selly21 device off as well.
Here's to script:

Code: Select all

-- switch-another

local pushOn2 = 'Piano aan'
local pushOff2 = 'Piano uit'
local Shelly21 = 'Groene lampjes'

return
{
    on =
    {
        devices =
        {
            pushOn2,
            pushOff2,
            Shelly21, 
        }, 
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change from LOG_DEBUG to domoticz.LOG_ERROR when all OK
        marker = 'piano lampjes',
    },

    execute = function(domoticz, item)
        -- domoticz.devices(pushOff2).dump()
        domoticz.log('0 pushOn2          : ' ..pushOn2 , domoticz.LOG_DEBUG)
        --domoticz.log('1 waarde van item is           : ' ..item, domoticz.LOG_DEBUG)
        domoticz.log('2 Groene lampjes   : ' ..domoticz.devices('Groene lampjes').state, domoticz.LOG_INFO)
        domoticz.log('2a Piano aan state   : '..domoticz.devices('Piano aan').state,domoticz.LOG_DEBUG)
        domoticz.log('2b Piano uit state   : '..domoticz.devices('Piano uit').state,domoticz.LOG_DEBUG)
        if item.name == 'pushOn2' and item.active then
            domoticz.devices(Shelly21).switchOn()
            domoticz.log('3 Groene lampjes pushOn2  : ' ..domoticz.devices('Groene lampjes').state, domoticz.LOG_INFO)
        end
        if item.name == 'pushOff2' and item.active  then  -- and item.active
            domoticz.devices(Shelly21).switchOff()
            domoticz.log('4 Groene lampjes pushOff2     : ' ..domoticz.devices('Groene lampjes').state, domoticz.LOG_INFO)
        end
    end
}
The trick lies in this part of the code: item.name == 'pushOn2' (I suppose)

Of course help is appreciated.
Bugs bug me.
Kedi
Posts: 575
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: Stuck with a script

Post by Kedi »

Why is in this part Shell21 present? I think you should remove it.

Code: Select all

        devices =
        {
            pushOn2,
            pushOff2,
            Shelly21, 
        }, 
While you at it this could also be changed

Code: Select all

        domoticz.log('2 Groene lampjes   : ' ..domoticz.devices('Groene lampjes').state, domoticz.LOG_INFO)
        domoticz.log('2a Piano aan state   : '..domoticz.devices('Piano aan').state,domoticz.LOG_DEBUG)
        domoticz.log('2b Piano uit state   : '..domoticz.devices('Piano uit').state,domoticz.LOG_DEBUG)
in

Code: Select all

        domoticz.log('2 Groene lampjes   : ' ..domoticz.devices(Shelly21).state, domoticz.LOG_INFO)
        domoticz.log('2a Piano aan state   : '..domoticz.devices(pushOn2).state,domoticz.LOG_DEBUG)
        domoticz.log('2b Piano uit state   : '..domoticz.devices(pushOff2).state,domoticz.LOG_DEBUG)
It is more consistent code.
Logic will get you from A to B. Imagination will take you everywhere.
HvdW
Posts: 615
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Stuck with a script

Post by HvdW »

@Kedi: thanks, that is a good start. All Shelly21 removed and consistent naming now.
Bugs bug me.
Kedi
Posts: 575
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: Stuck with a script

Post by Kedi »

Is it working now as intended?
Logic will get you from A to B. Imagination will take you everywhere.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest