Running perl script from within dzVents?

User avatar
thorbj
Posts: 183
Joined: Thursday 20 November 2014 23:11
Target OS: Raspberry Pi
Domoticz version: beta
Location: Norway
Contact:

Running perl script from within dzVents?

Postby thorbj » Tuesday 01 November 2016 10:16

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

User avatar
thorbj
Posts: 183
Joined: Thursday 20 November 2014 23:11
Target OS: Raspberry Pi
Domoticz version: beta
Location: Norway
Contact:

Re: Running perl script from within dzVents?

Postby thorbj » Tuesday 01 November 2016 23:02

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: 551
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: Running perl script from within dzVents?

Postby dannybloe » Wednesday 02 November 2016 9:30

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 - RPiB+ZWay - Aeotec MultiSensor (6x) - Fibaro/Popp/GreenWave wall plugs - TKB Home dimmer - Aeotec Door sensor - Toon - 2x FGD-212, 8x FGD-211, 3x Qubino Flush dimmers - EvoHome Wifi+HGI80 - ESPEasy

User avatar
thorbj
Posts: 183
Joined: Thursday 20 November 2014 23:11
Target OS: Raspberry Pi
Domoticz version: beta
Location: Norway
Contact:

Re: Running perl script from within dzVents?

Postby thorbj » Wednesday 02 November 2016 14:37

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: 6
Joined: Monday 30 March 2015 14:36
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Running perl script from within dzVents?

Postby lazara007 » Monday 05 December 2016 20:06

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
}

User avatar
thorbj
Posts: 183
Joined: Thursday 20 November 2014 23:11
Target OS: Raspberry Pi
Domoticz version: beta
Location: Norway
Contact:

Re: Running perl script from within dzVents?

Postby thorbj » Saturday 04 March 2017 13:11

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


Return to “dzVents Lua Framework”

Who is online

Users browsing this forum: No registered users and 2 guests