Isaksson / node-red-contrib-unifi

MIT License
51 stars 20 forks source link

Issues enabling and disabling a firewall rule. #84

Closed karldonteljames closed 1 year ago

karldonteljames commented 2 years ago

I'm trying to enable and disable a firewall rule, Ideally I would like to achieve this from an input boolean from inside home assistant, but I seem to be unable to get this working with a simple inject node. I've changed the option on the controller node under command, but cannot for the life of me get this working. Could you point me in the direction of getting this working please.

I have a copy of my flow below. [{"id":"528f84df.be5abc","type":"Unifi","z":"cb32f1eb.645ed","name":"Udmp Controller","server":"09ed191bfdbce337","command":"130","x":680,"y":280,"wires":[[]]},{"id":"7adf733e.35c48c","type":"function","z":"cb32f1eb.645ed","name":"Enable Wifi","func":"msg.payload = {command: \"disableWlan\",wlan_id: \"60baae61851b7906a4734e12\",disable: \"false\"}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":320,"wires":[["528f84df.be5abc"]]},{"id":"d56c4ab4.c406a8","type":"inject","z":"cb32f1eb.645ed","name":"enable Boys Internet","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{ command: \"disableFirewallRule\", rule_id: \"615dc5c9d71b350421e4dbe2\" }","payloadType":"str","x":410,"y":220,"wires":[["528f84df.be5abc"]]},{"id":"0c383198a81113e4","type":"inject","z":"cb32f1eb.645ed","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{command:\"disableWlan\",wlan_id:\"60baae61851b7906a4734e12\",disable:\"false\"}","payloadType":"str","x":150,"y":280,"wires":[["7adf733e.35c48c"]]},{"id":"56615909ca24e5fd","type":"inject","z":"cb32f1eb.645ed","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{ command: \"enableFirewallRule\", rule_id: \"615dc5c9d71b350421e4dbe2\" }","payloadType":"str","x":490,"y":80,"wires":[["528f84df.be5abc"]]},{"id":"09ed191bfdbce337","type":"unificonfig","name":"UDMP","ip":"192.168.10.254","port":"443","site":"default","unifios":true,"ssl":false}]

This was another option i tried. [{"id":"528f84df.be5abc","type":"Unifi","z":"cb32f1eb.645ed","name":"Udmp Controller","server":"09ed191bfdbce337","command":"1","x":680,"y":280,"wires":[[]]},{"id":"7adf733e.35c48c","type":"function","z":"cb32f1eb.645ed","name":"Enable Internet","func":"msg.payload = { command: \"disableFirewallRule\", rule_id: \"615dc5c9d71b350421e4dbe2\" }","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":280,"wires":[["528f84df.be5abc"]]},{"id":"0c383198a81113e4","type":"inject","z":"cb32f1eb.645ed","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":150,"y":280,"wires":[["7adf733e.35c48c"]]},{"id":"66fe58f37f6c562c","type":"function","z":"cb32f1eb.645ed","name":"Disable Internet","func":"msg.payload = { command: \"disableFirewallRule\", rule_id: \"615dc5c9d71b350421e4dbe2\" }","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":320,"wires":[["528f84df.be5abc"]]},{"id":"412fe656f436fa25","type":"inject","z":"cb32f1eb.645ed","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":150,"y":320,"wires":[["66fe58f37f6c562c"]]},{"id":"09ed191bfdbce337","type":"unificonfig","name":"UDMP","ip":"192.168.10.254","port":"443","site":"default","unifios":true,"ssl":false}]

Isaksson commented 2 years ago

Hello. I have imported your flows that you have tried with and I used the second one for reference and made some small modifications, do you get any error message or so if you run this flow?

[ { "id": "3fb21408fba8366a", "type": "debug", "z": "43cb15693bf2cc2c", "name": "debug 2", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 1800, "y": 580, "wires": [] }, { "id": "7af7d81e0e70f92c", "type": "Unifi", "z": "43cb15693bf2cc2c", "name": "Udmp Controller", "server": "09ed191bfdbce337", "command": "1", "x": 1600, "y": 580, "wires": [ [ "3fb21408fba8366a" ] ] }, { "id": "45cd745c8561ca77", "type": "function", "z": "43cb15693bf2cc2c", "name": "Enable Internet", "func": "msg.payload = { command: \"enableFirewallRule\", rule_id: \"615dc5c9d71b350421e4dbe2\" }\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1340, "y": 560, "wires": [ [ "7af7d81e0e70f92c" ] ] }, { "id": "383b7f3305697443", "type": "inject", "z": "43cb15693bf2cc2c", "name": "", "props": [], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "x": 1110, "y": 560, "wires": [ [ "45cd745c8561ca77" ] ] }, { "id": "a50c01ab313ea2a6", "type": "function", "z": "43cb15693bf2cc2c", "name": "Disable Internet", "func": "msg.payload = { command: \"disableFirewallRule\", rule_id: \"615dc5c9d71b350421e4dbe2\" }\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1340, "y": 600, "wires": [ [ "7af7d81e0e70f92c" ] ] }, { "id": "b82cfd85de9ec0c9", "type": "inject", "z": "43cb15693bf2cc2c", "name": "", "props": [], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "x": 1110, "y": 600, "wires": [ [ "a50c01ab313ea2a6" ] ] }, { "id": "09ed191bfdbce337", "type": "unificonfig", "name": "UDMP", "ip": "192.168.10.254", "port": "443", "site": "default", "unifios": true, "ssl": false } ]

karldonteljames commented 1 year ago

Sorry for the delay in coming back to this, the node comes back with this when i select the message state for complete message object. {"_msgid":"adb96608784fa0c6","payload":{"command":"enableFirewallRule","rule_id":"615dc5c9d71b350421e4dbe2"},"error":"ERR_BAD_REQUEST"}

karldonteljames commented 1 year ago

and if i try and run it again, no message comes up at all, just a red box image

Isaksson commented 1 year ago

Do you have the correct settings for your Unifi Controller? It looks like you use an UDMP, then you should select the Unifi OS checkbox in the settings of this node.

karldonteljames commented 1 year ago

Thank you so much for your help. Turns out I was running an old version of the code in node-red, i updated the version (once i figured out why no modules would upgrade) and all works as expected. Thanks again.