option to run cmd on switch open

This commit is contained in:
Elizabeth Cray 2024-12-17 23:36:02 -05:00
parent 7a71b0c216
commit bafe63bf0d
2 changed files with 11 additions and 1 deletions

View File

@ -27,7 +27,8 @@
"name": "",
"uniqueId": "",
"valueKey": "open",
"influxKey": "state"
"influxKey": "state",
"openScript": "this is optional"
}
]
}

View File

@ -1,6 +1,7 @@
import axios from 'axios'
import WebSocket from 'ws'
import fs from 'fs'
import exec from 'child_process'
let config = JSON.parse(fs.readFileSync('config.json', 'utf8'))
let ws = new WebSocket(`ws://${config.servers.deconz.url}:${config.servers.deconz.websocketPort}`)
@ -25,6 +26,14 @@ ws.on('message', msg => {
}).catch(error => {
console.error(error)
})
if (device.openScript){
console.log("Running open script")
try {
console.log(exec.execSync(device.openScript).toString())
} catch (error) {
console.error(error)
}
}
}
}
} catch (error) {