I’m testing with pimatic v0.9 which supports auto discovery. Now my coffee script is limited but I have a basic version working. Would be nice if someone could help with a better knowledge.
What i currently have:
@framework.deviceManager.on('discover', (eventData) =>
@framework.deviceManager.discoverMessage(
'pimatic-mysensors', "Searching for nodes"
)
# Received presentation message from the gateway
@board.on("rfPresent", (result) =>
newdevice = true
nodeid = result.sender
sensorid = result.sensor
sensortype = result.type
# Check if device already exists in pimatic
for device in @framework.deviceManager.devicesConfig
if device?.sensorid is sensorid and device?.nodeid is nodeid
newdevice = false
break
# Device is a new device
if newdevice is true
# Temp sensor found
if sensortype is S_TEMP
config = {
class: 'MySensorsDST',
nodeid: nodeid,
sensorid: sensorid
}
@framework.deviceManager.discoveredDevice(
'pimatic-mysensors', "Temp Sensor #{nodeid}", config
)
# PIR sensor found
if sensortype is S_MOTION
config = {
class: 'MySensorsPIR',
nodeid: nodeid,
sensorid: sensorid
}
@framework.deviceManager.discoveredDevice(
'pimatic-mysensors', "PIR Sensor #{nodeid}", config
)
# Contact sensor found
if sensortype is S_DOOR
config = {
class: 'MySensorsButton',
nodeid: nodeid,
sensorid: sensorid
}
@framework.deviceManager.discoveredDevice(
'pimatic-mysensors', "Contact Sensor #{nodeid}", config
)
# Light sensor found
if sensortype is S_LIGHT_LEVEL
config = {
class: 'MySensorsLight',
nodeid: nodeid,
sensorid: sensorid
}
@framework.deviceManager.discoveredDevice(
'pimatic-mysensors', "Light Sensor #{nodeid}", config
)
# Lux sensor found
if sensortype is S_LIGHT_LEVEL
config = {
class: 'MySensorsLux',
nodeid: nodeid,
sensorid: sensorid
}
@framework.deviceManager.discoveredDevice(
'pimatic-mysensors', "Lux Sensor #{nodeid}", config
)
# kWh sensor found
if sensortype is S_POWER
config = {
class: 'MySensorsPulseMeter',
nodeid: nodeid,
sensorid: sensorid
}
@framework.deviceManager.discoveredDevice(
'pimatic-mysensors', "kWh sensor #{nodeid}", config
)
# Water sensor found
if sensortype is S_WATER
config = {
class: 'MySensorsWaterMeter',
nodeid: nodeid,
sensorid: sensorid
}
@framework.deviceManager.discoveredDevice(
'pimatic-mysensors', "Water sensor #{nodeid}", config
)
# Switch found
if sensortype is S_LIGHT
config = {
class: 'MySensorsSwitch',
nodeid: nodeid,
sensorid: sensorid
}
@framework.deviceManager.discoveredDevice(
'pimatic-mysensors', "Switch #{nodeid}", config
)
# Dimmer found
if sensortype is S_DIMMER
config = {
class: 'MySensorsDimmer',
nodeid: nodeid,
sensorid: sensorid
}
@framework.deviceManager.discoveredDevice(
'pimatic-mysensors', "Dimmer #{nodeid}", config
)
)
)
Some questions:
I’m looking if a node is already in the config. Now i’m looking in a for loop if there is a same device. Is there a better way to check this?
pimatic says its searching for 20s, but it won’t stop after 20s