Running perl script from within dzVents?

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

Moderator: leecollings

Post Reply
thorbj
Posts: 113
Joined: Thursday 20 November 2014 22:11
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Norway
Contact:

Running perl script from within dzVents?

Post by thorbj »

How can i run a perl script using dzventz?
I have tried this:

Code: Select all

local OL_BULB_HALL = 153

return {
        active = true,                  -- set to true to activate this script
        on = {
                'OL_BULB_HALL',                 -- name of the device
        },

        execute = function(domoticz, OL_BULB_HALL)                               


        if (OL_BULB_HALL.state == 'Off') then
                 os.execute('/home/pi/domoticz/scrips/perl/bulb_off');
                end

        if (OL_BULB_HALL.state == 'On') then
                 os.execute('/home/pi/deomoticz/scripts/perl/bulb_on');
                end
        end
}
But nothings happens. No scripts is called when pressing the switch.

How can I do this?

Thanks.
2xRaspberry Pi Model 2 w/RaZberry z-wave chip (master/slave)|Fibaro Wall Plug|Fibaro Universal Dimmer 500W|Aeon Labs Multisensor|RFXtrx433E|Nexa WMR-1000|Nexa Pe-3|Nexa Remote|Nexa LGDR3500|Lightify Gateway|Lightify RGBW bulb
thorbj
Posts: 113
Joined: Thursday 20 November 2014 22:11
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Norway
Contact:

Re: Running perl script from within dzVents?

Post by thorbj »

I now have the following script running when a dummy switch is clicked:

Code: Select all

-- DEVICE INDEX
-- 161 Lightify bulb A60RGBW 01

local OL_BULB_HALL = 161

return {
        active = true,                  -- set to true to activate this script
        on = {
                OL_BULB_HALL,
        },

        execute = function(domoticz)

        local bulbHall = domoticz.devices[OL_BULB_HALL]


        if (bulbHall.state == 'off') then
                os.execute('~/Device-Osram-Lightify/bin/ol --hub 10.10.10.111 --name="A60RGBW 01" --Off')

         end

        if (bulbHall.state == 'on') then
                os.execute('~/Device-Osram-Lightify/bin/ol --hub 10.10.10.111 --name="A60RGBW 01" --On')
         end
        end
        }

It doesn't return any errors, but it doesn't execute the perl command either. Does anyone know what I'm doring wrong here?

This script gives the following log output when the dummy switch is clicked:

Code: Select all

2016-11-01 22:01:15.329 User: Admin initiated a switch command (161/Lightify1/Off)
2016-11-01 22:01:15.486 LUA: Handling events for: "Lightify1", value: "Off"
2016-11-01 22:01:15.486 LUA: =====================================================
2016-11-01 22:01:15.486 LUA: >>> Handler: perl
2016-11-01 22:01:15.486 LUA: >>> Device: "Lightify1" Index: 161
2016-11-01 22:01:15.486 LUA: .....................................................
2016-11-01 22:01:15.503 LUA: .....................................................
2016-11-01 22:01:15.503 LUA: <<< Done
2016-11-01 22:01:15.503 LUA: -----------------------------------------------------
2016-11-01 22:01:15.330 (Dummy switch) Lighting 1 (Lightify1)
2016-11-01 22:01:17.432 User: Admin initiated a switch command (161/Lightify1/On)
2016-11-01 22:01:17.610 LUA: Handling events for: "Lightify1", value: "On"
2016-11-01 22:01:17.610 LUA: =====================================================
2016-11-01 22:01:17.610 LUA: >>> Handler: perl
2016-11-01 22:01:17.611 LUA: >>> Device: "Lightify1" Index: 161
2016-11-01 22:01:17.611 LUA: .....................................................
2016-11-01 22:01:17.633 LUA: .....................................................
2016-11-01 22:01:17.633 LUA: <<< Done
2016-11-01 22:01:17.633 LUA: -----------------------------------------------------
2016-11-01 22:01:17.433 (Dummy switch) Lighting 1 (Lightify1)
Thanks!
2xRaspberry Pi Model 2 w/RaZberry z-wave chip (master/slave)|Fibaro Wall Plug|Fibaro Universal Dimmer 500W|Aeon Labs Multisensor|RFXtrx433E|Nexa WMR-1000|Nexa Pe-3|Nexa Remote|Nexa LGDR3500|Lightify Gateway|Lightify RGBW bulb
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Running perl script from within dzVents?

Post by dannybloe »

thorbj wrote:I now have the following script running when a dummy switch is clicked:

Code: Select all

-- DEVICE INDEX
-- 161 Lightify bulb A60RGBW 01

local OL_BULB_HALL = 161

return {
        active = true,                  -- set to true to activate this script
        on = {
                OL_BULB_HALL,
        },

        execute = function(domoticz)

        local bulbHall = domoticz.devices[OL_BULB_HALL]


        if (bulbHall.state == 'off') then
                os.execute('~/Device-Osram-Lightify/bin/ol --hub 10.10.10.111 --name="A60RGBW 01" --Off')

         end

        if (bulbHall.state == 'on') then
                os.execute('~/Device-Osram-Lightify/bin/ol --hub 10.10.10.111 --name="A60RGBW 01" --On')
         end
        end
        }

It doesn't return any errors, but it doesn't execute the perl command either. Does anyone know what I'm doring wrong here?

This script gives the following log output when the dummy switch is clicked:

Code: Select all

2016-11-01 22:01:15.329 User: Admin initiated a switch command (161/Lightify1/Off)
2016-11-01 22:01:15.486 LUA: Handling events for: "Lightify1", value: "Off"
2016-11-01 22:01:15.486 LUA: =====================================================
2016-11-01 22:01:15.486 LUA: >>> Handler: perl
2016-11-01 22:01:15.486 LUA: >>> Device: "Lightify1" Index: 161
2016-11-01 22:01:15.486 LUA: .....................................................
2016-11-01 22:01:15.503 LUA: .....................................................
2016-11-01 22:01:15.503 LUA: <<< Done
2016-11-01 22:01:15.503 LUA: -----------------------------------------------------
2016-11-01 22:01:15.330 (Dummy switch) Lighting 1 (Lightify1)
2016-11-01 22:01:17.432 User: Admin initiated a switch command (161/Lightify1/On)
2016-11-01 22:01:17.610 LUA: Handling events for: "Lightify1", value: "On"
2016-11-01 22:01:17.610 LUA: =====================================================
2016-11-01 22:01:17.610 LUA: >>> Handler: perl
2016-11-01 22:01:17.611 LUA: >>> Device: "Lightify1" Index: 161
2016-11-01 22:01:17.611 LUA: .....................................................
2016-11-01 22:01:17.633 LUA: .....................................................
2016-11-01 22:01:17.633 LUA: <<< Done
2016-11-01 22:01:17.633 LUA: -----------------------------------------------------
2016-11-01 22:01:17.433 (Dummy switch) Lighting 1 (Lightify1)
Thanks!
Strange. So you are sure that you end up in the if-parts. Could it be that it cannot find the script? Maybe try a relative path from the script's location?
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
thorbj
Posts: 113
Joined: Thursday 20 November 2014 22:11
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Norway
Contact:

Re: Running perl script from within dzVents?

Post by thorbj »

I'm pretty sure the if is correct, but I'm no expert in lua/perl/bash etc...

I tried changing to a relative path, but still nothing.

The script, perl.lua:

Code: Select all

-- DEVICE INDEX
-- 161 Lightify bulb A60RGBW 01

local OL_BULB_HALL = 161

return {
        active = true,                  -- set to true to activate this script
        on = {
                OL_BULB_HALL,
        },

        execute = function(domoticz)

        local bulbHall = domoticz.devices[OL_BULB_HALL]


if (bulbHall.state == "Off") then
                        os.execute('/home/pi/Device-Osram-Lightify/bin/ol --hub 10.10.10.111 --name="A60RGBW 01" --Off')
                        print("Lys gang av")
                end

if (bulbHall.state == "On") then
                    os.execute('/home/pi/Device-Osram-Lightify/bin/ol --hub 10.10.10.111 --name="A60RGBW 01" --On')
                        print("Lys gang på")
                end
end
}
Also it runs twice:

Code: Select all

2016-11-02 13:35:41.105 User: Admin initiated a switch command (161/Lightify1/Off)
2016-11-02 13:35:41.225 LUA: Handling events for: "Lightify1", value: "Off"
2016-11-02 13:35:41.225 LUA: =====================================================
2016-11-02 13:35:41.225 LUA: >>> Handler: perl
2016-11-02 13:35:41.225 LUA: >>> Device: "Lightify1" Index: 161
2016-11-02 13:35:41.225 LUA: .....................................................
2016-11-02 13:35:41.263 LUA: Lys gang av
2016-11-02 13:35:41.263 LUA: .....................................................
2016-11-02 13:35:41.264 LUA: <<< Done
2016-11-02 13:35:41.264 LUA: -----------------------------------------------------
2016-11-02 13:35:41.264 LUA: =====================================================
2016-11-02 13:35:41.264 LUA: >>> Handler: perl
2016-11-02 13:35:41.264 LUA: >>> Device: "Lightify1" Index: 161
2016-11-02 13:35:41.264 LUA: .....................................................
2016-11-02 13:35:41.312 LUA: Lys gang av
2016-11-02 13:35:41.312 LUA: .....................................................
2016-11-02 13:35:41.312 LUA: <<< Done
2016-11-02 13:35:41.312 LUA: -----------------------------------------------------
2016-11-02 13:35:41.106 (Dummy switch) Lighting 1 (Lightify1)
EDIT:
I've also made two perl scripts called bulb_off.pl and bulb_on.pl, and two bash scripts called lightify_bulb_on.sh, and lightify_bulb_off.sh. The bash scripts simply calls the perl scripts. They all work in shell.

I tried calling these scripts, both perl and bash, in the lua script instead of the ol --hub.... command. But no result here either.

Perl script bulb_on.pl

Code: Select all

#!/usr/bin/perl
use Device::Osram::Lightify::Hub;

my $x = Device::Osram::Lightify::Hub->new( host => "10.10.10.111" );

foreach my $light ( $x->lights() ) {
    if ( $light->name() eq "A60RGBW 01" ) {
        $light->set_on();
        exit(0);
    }
}
Bash script lightify_bulb_on.sh:

Code: Select all

#!/bin/bash
#!/usr/bin/perl
#!/home/pi/Device-Osram-Lightify/bin/ol
perl /home/pi/domoticz/scripts/perl/bulb_on.pl > /dev/null 2>&1 &
echo "lightify_bulb_on finished"; > /dev/null 2>&1 &
As a side note, I have tried running these scripts directly form the switch, this results in a 512 error. Maybe because of perl?
2xRaspberry Pi Model 2 w/RaZberry z-wave chip (master/slave)|Fibaro Wall Plug|Fibaro Universal Dimmer 500W|Aeon Labs Multisensor|RFXtrx433E|Nexa WMR-1000|Nexa Pe-3|Nexa Remote|Nexa LGDR3500|Lightify Gateway|Lightify RGBW bulb
lazara007
Posts: 14
Joined: Monday 30 March 2015 14:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Running perl script from within dzVents?

Post by lazara007 »

path was wrong, "t" was missing from srcipts (scrips)

Code: Select all

return {
   active = true,                  
   on = { 'wall_switch' },

   execute = function(domoticz, mySwitch) 
     
         if domoticz.devices['wall_switch'].state == 'On' then
            os.execute('/home/pi/domoticz/scripts/limitless_rgb.sh')
         else
            os.execute('/home/pi/domoticz/scripts/limitless_rgb_off.sh')
         end
      
   end
}
thorbj
Posts: 113
Joined: Thursday 20 November 2014 22:11
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Norway
Contact:

Re: Running perl script from within dzVents?

Post by thorbj »

lazara007 wrote:path was wrong, "t" was missing from srcipts (scrips)

Code: Select all

return {
   active = true,                  
   on = { 'wall_switch' },

   execute = function(domoticz, mySwitch) 
     
         if domoticz.devices['wall_switch'].state == 'On' then
            os.execute('/home/pi/domoticz/scripts/limitless_rgb.sh')
         else
            os.execute('/home/pi/domoticz/scripts/limitless_rgb_off.sh')
         end
      
   end
}
Haha, that was embarrassing... Thanks!
2xRaspberry Pi Model 2 w/RaZberry z-wave chip (master/slave)|Fibaro Wall Plug|Fibaro Universal Dimmer 500W|Aeon Labs Multisensor|RFXtrx433E|Nexa WMR-1000|Nexa Pe-3|Nexa Remote|Nexa LGDR3500|Lightify Gateway|Lightify RGBW bulb
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests