OK i did make a prototype implementation using the V_CUSTOM message type.
This works for Vera only.
I had to change only one file: L_Arduino.lua
The function starting on line 244 has te be extened with this if statement:
-- Handle Local Request variables
if (varType == "CUSTOM") then
local bit = require("bit")
local varReqIndex = bit.band(tonumber(value), 0xFF);
local varVeraId = bit.rshift(tonumber(value), 8);
local varReqType = tVarLookupNumType[varReqIndex]
local varReq = tVarTypes[varReqType]
if (varReq[2] ~= nil) then
log("Local request '" .. varReq[3] .. "' from Device ID: ".. varVeraId .. " sensor type '" .. varReqType .. "'")
local localValue = luup.variable_get(varReq[2], varReq[3], varVeraId)
if (localValue ~= nil) then
-- Send variable value to actuator
sendRequestResponse(nodeId .. ";" .. childId, varReqType, localValue)
end
end
else
The complete function will then look like this:
local function setVariable(incomingData, childId, nodeId)
if (childId ~= nil) then
-- Set variable on child sensor.
local index = tonumber(incomingData[5]);
local varType = tVarLookupNumType[index]
local var = tVarTypes[varType]
local value = incomingData[6]
local timestamp = os.time()
-- Handle Local Request variables
if (varType == "CUSTOM") then
local bit = require("bit")
local varReqIndex = bit.band(tonumber(value), 0xFF);
local varVeraId = bit.rshift(tonumber(value), 8);
local varReqType = tVarLookupNumType[varReqIndex]
local varReq = tVarTypes[varReqType]
if (varReq[2] ~= nil) then
log("Local request '" .. varReq[3] .. "' from Device ID: ".. varVeraId .. " sensor type '" .. varReqType .. "'")
local localValue = luup.variable_get(varReq[2], varReq[3], varVeraId)
if (localValue ~= nil) then
-- Send variable value to actuator
sendRequestResponse(nodeId .. ";" .. childId, varReqType, localValue)
end
end
elseif (var[2] ~= nil) then
log("Setting variable '".. var[3] .. "' to value '".. value.. "'")
setVariableIfChanged(var[2], var[3], value, childId)
-- Handle special variables battery level and tripped which also
-- should update other variables to os.time()
if (varType == "TRIPPED" and value == "1") then
local variable = tVeraTypes["LAST_TRIP"]
setVariableIfChanged(variable[2], variable[3], timestamp, childId)
else
local variable = tVeraTypes["LAST_UPDATE"]
setVariableIfChanged(variable[2], variable[3], timestamp, childId)
end
end
-- Always update LAST_UPDATE for node
if (nodeId ~= nil) then
local nodeDevice = childIdLookupTable[nodeId .. ";" .. NODE_CHILD_ID]
setLastUpdate(nodeDevice)
end
end
end
Now the Vera HA-contoller response on V_CUSTOM messages.
Use the feature in a MySensors node:
void requestValue(byte type, unsigned int id)
{
MyMessage msgRequest(1, V_CUSTOM);
unsigned long msgData;
msgData = type + ((unsigned long)id * 0x100);
send(msgRequest.set(msgData));
}
void loop()
{
// Request the status from Vera Device 4
requestValue(V_STATUS, 4);
// Request the dimn level from Vera Device 20
requestValue(V_LEVEL, 20);
// etc..
}
Make sure you can handle the incoming messages
void receive(const MyMessage &message)
{
if (message.type==V_STATUS) {
Serial.print(" New value: ");
Serial.println(message.getBool());
}
if (message.type==V_LEVEL) {
Serial.print(" New value: ");
Serial.println(message.getByte());
}
if (message.type==V_TEMP) {
Serial.print(" New value: ");
Serial.println(message.getFloat());
}
}
If you need the same value type from different Device a different sensor id can be used, the requestValue will then look like this:
void requestValue(byte type, unsigned int id, byte sensorid)
{
MyMessage msgRequest(sensorid, V_CUSTOM);
unsigned long msgData;
msgData = type + ((unsigned long)id * 0x100);
send(msgRequest.set(msgData));
}
In the receive function "message.sensor" can be used to determine for which device a request was made