Help with LUA - updating status?

Moderator: leecollings

Post Reply
Rena
Posts: 19
Joined: Monday 21 September 2015 20:17
Target OS: Raspberry Pi / ODroid
Domoticz version: V 3.8153
Location: Sweden
Contact:

Help with LUA - updating status?

Post by Rena »

Hi,

I have a Rasp running SPC Web Gateway, Domoticz and a binding between Web Gateway and Domoticz.

I would like have a dummy switch which shows if the alarm is on or off. With help from other forums I have managed to get the user variables from Web Gateway.
Variabler.JPG
Variabler.JPG (85.52 KiB) Viewed 2128 times
I have also mananged to write a lua-script and add a dummy-switch that shows alarm-status.

commandArray = {}
logging = true
if (uservariablechanged['G_SPC_AREA_MODE_1'] == 'unset') then
commandArray['House Alarm Set/Unset']='Off'
elseif (uservariablechanged['G_SPC_AREA_MODE_1'] == 'set') then
commandArray['House Alarm Set/Unset']='On'
end

return commandArray


That worked well when I tried yesterday, but then I changed to this (just to get Swedish terms). I also changed name on the dummy switch to "Larm" but now it doesn´t work.

commandArray = {}
logging = true
if (uservariablechanged['G_SPC_AREA_MODE_1'] == 'unset') then
commandArray['Larm']='Off'
elseif (uservariablechanged['G_SPC_AREA_MODE_1'] == 'set') then
commandArray['Larm']='On'
end

return commandArray


Any suggestion to why it doesn´t work? I have tried to reboot everything, but still doesn´t work.

I´m a totally newbie to this.
jannl
Posts: 625
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Help with LUA - updating status?

Post by jannl »

Did you switch the Larm sensor at least once manually? This sometimes helped at my place.
User avatar
nayr
Posts: 354
Joined: Tuesday 11 November 2014 18:42
Target OS: Linux
Domoticz version: github
Location: Denver, CO - USA
Contact:

Re: Help with LUA - updating status?

Post by nayr »

after renaming a device it has to get a status update/change to actually take the rename, until then its its holding onto the previous name.
Debian Jessie: CuBox-i4 (Primary) w/Static Routed IP and x509 / BeagleBone with OpenSprinkler / BeagleBone Planted Aquarium / 3x Raspbery Pi2b GPIO Slaves
Elemental Theme - node-domoticz-mqtt - Home Theatre Controller - AndroidTV Simple OSD Remote - x509 TLS Auth
Rena
Posts: 19
Joined: Monday 21 September 2015 20:17
Target OS: Raspberry Pi / ODroid
Domoticz version: V 3.8153
Location: Sweden
Contact:

Re: Help with LUA - updating status?

Post by Rena »

jannl wrote:Did you switch the Larm sensor at least once manually? This sometimes helped at my place.

Tried this, didn't work.
Rena
Posts: 19
Joined: Monday 21 September 2015 20:17
Target OS: Raspberry Pi / ODroid
Domoticz version: V 3.8153
Location: Sweden
Contact:

Re: Help with LUA - updating status?

Post by Rena »

nayr wrote:after renaming a device it has to get a status update/change to actually take the rename, until then its its holding onto the previous name.
I was thinking about this but don't know how to do this. Where to update?

And another question. Can I edit the lua-script while Domoticz is running?
User avatar
nayr
Posts: 354
Joined: Tuesday 11 November 2014 18:42
Target OS: Linux
Domoticz version: github
Location: Denver, CO - USA
Contact:

Re: Help with LUA - updating status?

Post by nayr »

Toggling the switch should have been enough to do it.. all you have to do is get the time to update on lastupdated really.

Yeah you can edit them safely while its running, your edits are not written until you actually save it.

try another name? Perhaps there is another device with that name messing things up.
Debian Jessie: CuBox-i4 (Primary) w/Static Routed IP and x509 / BeagleBone with OpenSprinkler / BeagleBone Planted Aquarium / 3x Raspbery Pi2b GPIO Slaves
Elemental Theme - node-domoticz-mqtt - Home Theatre Controller - AndroidTV Simple OSD Remote - x509 TLS Auth
Rena
Posts: 19
Joined: Monday 21 September 2015 20:17
Target OS: Raspberry Pi / ODroid
Domoticz version: V 3.8153
Location: Sweden
Contact:

Re: Help with LUA - updating status?

Post by Rena »

Now I have found the problem, but I don´t know how to fix it.
The problem is that the binding between Web Gateway and Domoticz are shut down when I close Putty. Is there any way to make the binding start automatically and most important of all, run in the background?

I run this binding https://github.com/fergalom/node-spc-do ... /README.md

Thanks!
User avatar
nayr
Posts: 354
Joined: Tuesday 11 November 2014 18:42
Target OS: Linux
Domoticz version: github
Location: Denver, CO - USA
Contact:

Re: Help with LUA - updating status?

Post by nayr »

This is how I run my NodeJS Scripts:

In the same folder as your node-spc-domoticz-binding.js
npm -g install daemonize2

Create a file called node-spc-domoticz-daemon.js, make it executable when your done (chmod +x node-spc-domoticz-daemon.js)

Code: Select all

#!/usr/bin/nodejs
var daemon = require("daemonize2").setup({
    main: "node-spc-domoticz-binding.js",
    name: "node-spc-domoticz-binding",
    pidfile: "node-spc-domoticz-binding.pid"
});

switch (process.argv[2]) {

    case "start":
        daemon.start();
        break;

    case "stop":
        daemon.stop();
        break;

    default:
        console.log("Usage: [start|stop]");
}
Then in your crontab you can put:
*/5 * * * * ~/path/to/node-spc-domoticz-daemon.js start

This will attempt to start it every 5mins in the background, if its not already running.
Debian Jessie: CuBox-i4 (Primary) w/Static Routed IP and x509 / BeagleBone with OpenSprinkler / BeagleBone Planted Aquarium / 3x Raspbery Pi2b GPIO Slaves
Elemental Theme - node-domoticz-mqtt - Home Theatre Controller - AndroidTV Simple OSD Remote - x509 TLS Auth
Rena
Posts: 19
Joined: Monday 21 September 2015 20:17
Target OS: Raspberry Pi / ODroid
Domoticz version: V 3.8153
Location: Sweden
Contact:

Re: Help with LUA - updating status?

Post by Rena »

nayr wrote:This is how I run my NodeJS Scripts:

In the same folder as your node-spc-domoticz-binding.js
npm -g install daemonize2

Create a file called node-spc-domoticz-daemon.js, make it executable when your done (chmod +x node-spc-domoticz-daemon.js)

Code: Select all

#!/usr/bin/nodejs
var daemon = require("daemonize2").setup({
    main: "node-spc-domoticz-binding.js",
    name: "node-spc-domoticz-binding",
    pidfile: "node-spc-domoticz-binding.pid"
});

switch (process.argv[2]) {

    case "start":
        daemon.start();
        break;

    case "stop":
        daemon.stop();
        break;

    default:
        console.log("Usage: [start|stop]");
}
Then in your crontab you can put:
*/5 * * * * ~/path/to/node-spc-domoticz-daemon.js start

This will attempt to start it every 5mins in the background, if its not already running.
Thanks - will try this!
fergalom
Posts: 74
Joined: Thursday 24 September 2015 11:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Help with LUA - updating status?

Post by fergalom »

hi Rena,
glad to hear you got it up and running

I use pm2 to run node-spc-domoticz-binding and it will also restart it should it stop for some reason.
Also survives reboots of the rasp-pi
http://pm2.keymetrics.io/

F
Rena
Posts: 19
Joined: Monday 21 September 2015 20:17
Target OS: Raspberry Pi / ODroid
Domoticz version: V 3.8153
Location: Sweden
Contact:

Re: Help with LUA - updating status?

Post by Rena »

nayr wrote:This is how I run my NodeJS Scripts:

In the same folder as your node-spc-domoticz-binding.js
npm -g install daemonize2

Create a file called node-spc-domoticz-daemon.js, make it executable when your done (chmod +x node-spc-domoticz-daemon.js)

Code: Select all

#!/usr/bin/nodejs
var daemon = require("daemonize2").setup({
    main: "node-spc-domoticz-binding.js",
    name: "node-spc-domoticz-binding",
    pidfile: "node-spc-domoticz-binding.pid"
});

switch (process.argv[2]) {

    case "start":
        daemon.start();
        break;

    case "stop":
        daemon.stop();
        break;

    default:
        console.log("Usage: [start|stop]");
}
Then in your crontab you can put:
*/5 * * * * ~/path/to/node-spc-domoticz-daemon.js start

This will attempt to start it every 5mins in the background, if its not already running.
trying to do this, I got problems with Crontab. Any ideas?

First I write "sudo crontab -e"
pi@raspberrypi ~ $ sudo crontab -e

After I have written in the crontab file and save it, the below text comes up in Putty.

no crontab for root - using an empty one
crontab: installing new crontab
"/tmp/crontab.IrAEuT/crontab":24: bad command
errors in crontab file, can't install.
Do you want to retry the same edit? (y/n)

What´s the problem?
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: Help with LUA - updating status?

Post by stlaha2007 »

two questions...

What have you tried to put into your crontab (perhaps make a screendump[just select the text when you have a putty-session open and paste it here])

Why sudo crontab -e? cron will run under user pi also. There is no need to run it as root.

Grtz,
Stephan
Rena
Posts: 19
Joined: Monday 21 September 2015 20:17
Target OS: Raspberry Pi / ODroid
Domoticz version: V 3.8153
Location: Sweden
Contact:

Re: Help with LUA - updating status?

Post by Rena »

stlaha2007 wrote:two questions...

What have you tried to put into your crontab (perhaps make a screendump[just select the text when you have a putty-session open and paste it here])

Why sudo crontab -e? cron will run under user pi also. There is no need to run it as root.

Grtz,
Stephan
Hi,

I will post when at home next time.

I don´t really know why sudo, I´m a totally newbie and have read it´s better to run my application as sudo.
Tried to run it as user pi, but same problem.

I will come back later this week.
Rena
Posts: 19
Joined: Monday 21 September 2015 20:17
Target OS: Raspberry Pi / ODroid
Domoticz version: V 3.8153
Location: Sweden
Contact:

Re: Help with LUA - updating status?

Post by Rena »

Screenshot from putty, same problem even if I´m running as "pi"
crontab.JPG
crontab.JPG (20.46 KiB) Viewed 1774 times
Suggestions?
jannl
Posts: 625
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Help with LUA - updating status?

Post by jannl »

What if you sudo first and after that crontab -e?
Rena
Posts: 19
Joined: Monday 21 September 2015 20:17
Target OS: Raspberry Pi / ODroid
Domoticz version: V 3.8153
Location: Sweden
Contact:

Re: Help with LUA - updating status?

Post by Rena »

I tried PM2 as Fergalom suggested, works great and was easy to use.
Case closed!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest