Page 1 of 1
Fritz Presence via TR64 using NodeRed
Posted: Tuesday 05 February 2019 16:38
by emme
Ciao,
based on the
great work in gathering the presence from the fritzBox using the ARP/DHCP lease tabel for devices, I used to do the same but using nodered. her eis the flow:

- FritzTR64.jpg (45.25 KiB) Viewed 1689 times
- Spoiler: show
- [{"id":"e4fbaee1.690b3","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"252c212b.e222be","type":"inject","z":"e4fbaee1.690b3","name":"injectRequest","topic":"","payload":"[{\"NewMACAddress\":\"94:FE:22:F2:D1:A2\"},{\"NewMACAddress\":\"40:9C:28:2D:BC:A3\"}]","payloadType":"json","repeat":"600","crontab":"","once":false,"onceDelay":0.1,"x":132,"y":77,"wires":[["de401f57.eb358"]]},{"id":"5b0bc536.5d486c","type":"fritzbox-in","z":"e4fbaee1.690b3","device":"","name":"TR69.presence","service":"urn:dslforum-org:service:Hosts:1","action":"GetSpecificHostEntry","arguments":"{\"NewMACAddress\":\"value\"}","x":359,"y":77,"wires":[["6764a833.1f81a8"]]},{"id":"6764a833.1f81a8","type":"json","z":"e4fbaee1.690b3","name":"","property":"payload","action":"obj","pretty":false,"x":457,"y":130,"wires":[["9a04354d.3c8888"]]},{"id":"9a04354d.3c8888","type":"function","z":"e4fbaee1.690b3","name":"FritzPresence 2 Domoticz","func":"var preMsg = {};\npreMsg.payload = {};\n\nvar preMap = {\n '<hostName as it appears in fritz>' : {\"command\": \"switchlight\", \"idx\": <DomoticzIdx>, \"switchcmd\": setOnOff(parseInt(msg.payload.NewActive),false) },\n};\n\nreturn {\"topic\": msg.payload.NewHostName , \"payload\": preMap[msg.payload.NewHostName]};\n\n\nfunction setOnOff(curValue, invert) {\n switch (curValue) {\n case 0:\n if (invert === false) {\n return \"Off\"\n } else {\n return \"On\";\n }\n break;\n case 1:\n if (invert === false) {\n return \"On\"\n } else {\n return \"Off\";\n }\n break;\n }\n}","outputs":1,"noerr":4,"x":615,"y":76,"wires":[["efa0aa25.90f2e8"]]},{"id":"efa0aa25.90f2e8","type":"rbe","z":"e4fbaee1.690b3","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":690,"y":129,"wires":[[]]},{"id":"de401f57.eb358","type":"function","z":"e4fbaee1.690b3","name":"Mac Request","func":"return [[\n { \"payload\" : {\n \"NewMACAddress\": \"AA:BB:CC:DD:EE:FF\"\n }\n },\n { \"payload\" : {\n \"NewMACAddress\": \"FF:AA:BB:CC:DD:EE\"\n }\n }\n]];","outputs":1,"noerr":0,"x":255,"y":135,"wires":[["5b0bc536.5d486c"]]}]
the flow inject a request every 10 minutes to the mac request node that contain the mac address to request, the messages goes to the Fritz.In node that returns a message for each device with the status.
Status goes to the FritzPresence 2 Domoticz that decode the hostname to a MQTT telegram with the correct IDX, a RBE node prevent multiple messages with the same payload.
To configure it you have to:
Node
MAC REQUEST: enter the Mac Address as shown.
Node
Fritz.In: configure your router connection
Node
FritzPresence 2 Domoticz : enter the Hostname as shown in the Fritz UI and the IDX of your virtual switch
deplay it and enjoy!

ciao
M
Re: Fritz Presence via TR64 using NodeRed
Posted: Tuesday 05 February 2019 22:17
by funky
Nice work! can you make a tutorial how to implement? For example how to save this file and where to run it. What are the depencencies etc..
Re: Fritz Presence via TR64 using NodeRed
Posted: Wednesday 06 February 2019 9:20
by emme
the only requirement is
node-red-contrib-fritz
Nodes Condifuration:
MAC request
this is used to list the Mac address you want to retrieve
Code: Select all
return [[
{ "payload" : {
"NewMACAddress": "AA:BB:CC:DD:EE:FF"
}
},
{ "payload" : {
"NewMACAddress": "FF:EE:DD:CC:BB:AA"
}
}
]];
add as many as you need
The Fritz TR node needs to be configured with the oruter address, user and pass
FritzPresence 2 Domoticz
this is used to parse the hostname to the virtual switch IDX in domoticz:
Code: Select all
var preMap = {
'hostname' : {"command": "switchlight", "idx": IDX, "switchcmd": setOnOff(parseInt(msg.payload.NewActive),false) }
};
you have to replace
hostname with the name as shown in the fritz LAN host view
then you have to replace the IDX with the device IDX avaliable in the device table view in domoticz