Page 1 of 1

Help with LUA - updating status?

Posted: Saturday 16 January 2016 10:17
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 2127 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.

Re: Help with LUA - updating status?

Posted: Saturday 16 January 2016 10:51
by jannl
Did you switch the Larm sensor at least once manually? This sometimes helped at my place.

Re: Help with LUA - updating status?

Posted: Saturday 16 January 2016 10:56
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.

Re: Help with LUA - updating status?

Posted: Saturday 16 January 2016 11:04
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.

Re: Help with LUA - updating status?

Posted: Saturday 16 January 2016 11:06
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?

Re: Help with LUA - updating status?

Posted: Saturday 16 January 2016 11:58
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.

Re: Help with LUA - updating status?

Posted: Saturday 16 January 2016 17:00
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!

Re: Help with LUA - updating status?

Posted: Saturday 16 January 2016 21:13
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.

Re: Help with LUA - updating status?

Posted: Monday 18 January 2016 15:00
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!

Re: Help with LUA - updating status?

Posted: Monday 18 January 2016 15:45
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

Re: Help with LUA - updating status?

Posted: Sunday 13 March 2016 16:47
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?

Re: Help with LUA - updating status?

Posted: Sunday 13 March 2016 17:09
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

Re: Help with LUA - updating status?

Posted: Tuesday 15 March 2016 8:38
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.

Re: Help with LUA - updating status?

Posted: Thursday 17 March 2016 18:42
by Rena
Screenshot from putty, same problem even if I´m running as "pi"
crontab.JPG
crontab.JPG (20.46 KiB) Viewed 1773 times
Suggestions?

Re: Help with LUA - updating status?

Posted: Friday 18 March 2016 7:35
by jannl
What if you sudo first and after that crontab -e?

Re: Help with LUA - updating status?

Posted: Friday 18 March 2016 8:42
by Rena
I tried PM2 as Fergalom suggested, works great and was easy to use.
Case closed!