Help with LUA - updating status?
Moderator: leecollings
-
- 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?
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.
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.
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.
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.
-
- 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?
Did you switch the Larm sensor at least once manually? This sometimes helped at my place.
- 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?
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
Elemental Theme - node-domoticz-mqtt - Home Theatre Controller - AndroidTV Simple OSD Remote - x509 TLS Auth
-
- 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?
jannl wrote:Did you switch the Larm sensor at least once manually? This sometimes helped at my place.
Tried this, didn't work.
-
- 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?
I was thinking about this but don't know how to do this. Where to update?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.
And another question. Can I edit the lua-script while Domoticz is running?
- 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?
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.
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
Elemental Theme - node-domoticz-mqtt - Home Theatre Controller - AndroidTV Simple OSD Remote - x509 TLS Auth
-
- 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?
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!
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!
- 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?
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)
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.
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]");
}
*/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
Elemental Theme - node-domoticz-mqtt - Home Theatre Controller - AndroidTV Simple OSD Remote - x509 TLS Auth
-
- 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?
Thanks - will try this!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)Then in your crontab you can put: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]"); }
*/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.
-
- Posts: 74
- Joined: Thursday 24 September 2015 11:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Help with LUA - updating status?
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
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
-
- 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?
trying to do this, I got problems with Crontab. Any ideas?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)Then in your crontab you can put: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]"); }
*/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.
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?
-
- Posts: 370
- Joined: Monday 05 October 2015 10:16
- Target OS: -
- Domoticz version:
- Contact:
Re: Help with LUA - updating status?
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
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
-
- 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?
Hi,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
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.
-
- 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?
Screenshot from putty, same problem even if I´m running as "pi"
Suggestions?
Suggestions?
-
- 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?
What if you sudo first and after that crontab -e?
-
- 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?
I tried PM2 as Fergalom suggested, works great and was easy to use.
Case closed!
Case closed!
Who is online
Users browsing this forum: No registered users and 1 guest