MCP23017 relay control

Hi

I'm hoping this is the right place to post this question...

I'm using the ncd-red-mcp23017 node with a 16 channel relay board.

For now, I would like to use it to switch the lights on in the house (we are rewiring), has anyone done something similar or know of an example to follow?

I'm want to control it both over MQTT as well as another MCP23017 with a switch for each light.

I would do this by defining a topic for each light (home/bedroom/ceilinglight for example or home/lights/bedroomceiling or however you decide to arrange the hierarchy) with values On and Off (or 1 and 0 or whatever standard you opt for).
Then have an mqtt in node for each topic and send it to the mcp23017 node with a change node in between if necessary to format the data for the mcp23017.

Then, likely on a different flow tab, have the dashboard nodes with the light switches and feed those out to MQTT with the appropriate topics for the lights. Make the topics Retained in MQTT so that the state will be remembered over power down (assuming that is what you want to do). Also have MQTT In nodes feeding the switch state back in to the front of the switch so that the switch goes to the right state matching the light on startup, and also if you have some logic that automatically switches the lights off or on (via MQTT again) then the switch will follow the current state. Make sure you clear the Message Passthrough checkbox on the switches otherwise you may get an mqtt loop.

By the way, I think it is node-red-contrib-mcp23017.

If you are in the position of wiring your house up now - then head over to https://www.superhouse.tv/ website and have a look at his stuff over there - basically he uses a central Arduino Mega (Eithermega in his case) and 12v switches everywhere which feedback to a central rack and he controls it all from there.

He sells the PCBs and switches etc as kits if you want to buy them

Also runs a Youtube channel where he shows it all off - including the technical build etc

Craig

Don't overdesign the new home. Someday you will want to sell the house and the odds are that the buyer will not appreciate a smart-home. If only you can maintain the system, it's of no value to the future occupant. The building code may require it, but make sure there is a conventional wiring/lighting system in addition to your smart wiring.

2 Likes

Hi Colin

Thanks for the advice, I didn't know the retain part and thanks for pointing out the message passthrough checkbox, I will look into that.

I am actually using the ncd-red-mcp23017 as I can't get the other one to install. I would have liked to try it.
I'm not familiar enough with javascript to get the formatting right, I would like it to be home/lights/bedroom1 etc, but the node I'm using wants the topic to be channel_1 channel_2... and then 1/0 for on and off.

Hi Craig

Thanks for pointing out that channel I will definitely check it out.

Hi Steve

That won't be a problem, as the house is on our family farm and won't be sold this generation, I am making sure I am up to code though.

1 Like

Something like this maybe

[{"id":"5b7b0b7d.9d00e4","type":"mqtt in","z":"6dc690a3.1abc88","name":"","topic":"home/bedroom1/lights","qos":"1","broker":"35776abd.9e4316","x":129.4444580078125,"y":177.7777557373047,"wires":[["c31b7a53.f64b38"]]},{"id":"6cee27a9.bbad78","type":"mqtt in","z":"6dc690a3.1abc88","name":"","topic":"home/bedroom2/lights","qos":"1","broker":"35776abd.9e4316","x":126.66668701171875,"y":291.1111145019531,"wires":[["57f0306b.bb955"]]},{"id":"c31b7a53.f64b38","type":"change","z":"6dc690a3.1abc88","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"channel_1","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"payload=\"On\" ? 1 : 0","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":366.1111111111111,"y":176.66666666666666,"wires":[["e26f4fac.60755"]]},{"id":"e26f4fac.60755","type":"debug","z":"6dc690a3.1abc88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":790.5556030273438,"y":215.55557250976562,"wires":[]},{"id":"57f0306b.bb955","type":"change","z":"6dc690a3.1abc88","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"channel_4","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"payload=\"On\" ? 1 : 0","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":292.22222900390625,"wires":[["e26f4fac.60755"]]},{"id":"8a66b554.019408","type":"comment","z":"6dc690a3.1abc88","name":"mcp23017 node here","info":"","x":603.8889770507812,"y":220,"wires":[]},{"id":"35776abd.9e4316","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
1 Like

Yep thats the beauty of how John (Superhouse.TV) has done his - pulled all standard wiring to each location but also a CAT6 - he leaves the standard wiring disconnected (well in truth actually permanently connected) and then a relay inline that is controlled by the Home Automation system.

Ever want to rip it all out - just take the 12v switches out - put in standard ones and remove the relays from near each light fixture

Having said that - in 10 years time i think everyone will expect some form of Home Automation and will be surprised if it is not in place on a newer house.

A lot of thought has to be put in as it is deployed to make sure it is modular and bits and pieces can be dropped in and out - so it can go from a tinkerers hobby house to one that is controlled by a big name set of products if that is what someone wants.

Craig