Compare commits
2 Commits
a8460bbfd7
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 960e2dc180 | |||
| 6ae4854180 |
@@ -1,3 +1,6 @@
|
|||||||
config.json
|
config.json
|
||||||
devices.json
|
devices.json
|
||||||
node_modules/
|
node_modules/
|
||||||
|
run.sh
|
||||||
|
watch.sh
|
||||||
|
dec0ntamination.service
|
||||||
|
|||||||
Executable
+38
@@ -0,0 +1,38 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
npm install
|
||||||
|
|
||||||
|
cat <<EOF> run.sh
|
||||||
|
#!/bin/bash
|
||||||
|
cd `pwd`
|
||||||
|
`which node` run.js
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat <<EOF> watch.sh
|
||||||
|
#!/bin/bash
|
||||||
|
cd `pwd`
|
||||||
|
`which node` watcher.js
|
||||||
|
EOF
|
||||||
|
|
||||||
|
chmod +x run.sh watch.sh
|
||||||
|
|
||||||
|
cat <<EOF> dec0ntamination.service
|
||||||
|
[Unit]
|
||||||
|
Description=Deconz Logger to Influx and Door Chime
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=`pwd`/watch.sh
|
||||||
|
Restart=always
|
||||||
|
RestartSec=10
|
||||||
|
User=1000
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
|
||||||
|
sudo cp dec0ntamination.service /etc/systemd/system/dec0ntamination.service
|
||||||
|
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
|
||||||
|
sudo systemctl enable --now dec0ntamination.service
|
||||||
+14
-6
@@ -24,7 +24,7 @@ ws.on('message', msg => {
|
|||||||
if (data.state) {
|
if (data.state) {
|
||||||
let device = config.wsDevices.find(device => device.uniqueId === data.uniqueid)
|
let device = config.wsDevices.find(device => device.uniqueId === data.uniqueid)
|
||||||
if (device) {
|
if (device) {
|
||||||
let payloadValue = (device.valueKey=='open')?(data.state['open']?0:1):data.state[device.valueKey]
|
let payloadValue = (device.valueKey == 'open') ? (data.state['open'] ? 0 : 1) : data.state[device.valueKey]
|
||||||
let influxPayload = `${device.name} ${device.influxKey}=${payloadValue}`
|
let influxPayload = `${device.name} ${device.influxKey}=${payloadValue}`
|
||||||
console.log(`${new Date().toString()} 👉🏻 Sending ${influxPayload}`)
|
console.log(`${new Date().toString()} 👉🏻 Sending ${influxPayload}`)
|
||||||
axios.post(`${config.servers.influx.url}/api/v2/write?orgID=${config.servers.influx.orgId}&bucket=${config.servers.influx.bucket}`,
|
axios.post(`${config.servers.influx.url}/api/v2/write?orgID=${config.servers.influx.orgId}&bucket=${config.servers.influx.bucket}`,
|
||||||
@@ -39,21 +39,29 @@ ws.on('message', msg => {
|
|||||||
console.log(response.data)
|
console.log(response.data)
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
console.log("ERROR")
|
console.log("ERROR")
|
||||||
})
|
})
|
||||||
if (device.openScript && data.state[device.valueKey]){
|
if (device.openScript && data.state[device.valueKey]) {
|
||||||
console.log("Running open script")
|
console.log("Running open script")
|
||||||
|
let scriptToRun = device.openScript.replace("%VALUE%", payloadValue)
|
||||||
try {
|
try {
|
||||||
exec.exec(device.openScript)
|
|
||||||
|
exec.exec(scriptToRun, (error, stdout, stderr) => {
|
||||||
|
if (error || stderr) {
|
||||||
|
console.error(`Error executing script: ${error ? error.message : stderr}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(`Script output: ${stdout}`);
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
console.log("ERROR")
|
console.log("ERROR")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
console.log("ERROR")
|
console.log("ERROR")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user