Fritz Presence via TR64 using NodeRed

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Fritz Presence via TR64 using NodeRed

Post 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
FritzTR64.jpg (45.25 KiB) Viewed 1687 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! :P
ciao
M
The most dangerous phrase in any language is:
"We always done this way"
funky
Posts: 75
Joined: Saturday 06 May 2017 22:38
Target OS: Raspberry Pi / ODroid
Domoticz version: newest
Location: Zeist, Netherlands
Contact:

Re: Fritz Presence via TR64 using NodeRed

Post 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..
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Fritz Presence via TR64 using NodeRed

Post 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
The most dangerous phrase in any language is:
"We always done this way"
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest