Use non-relay buttons on SwitchMote for garage status / operation

Started by detroit_johnny, October 20, 2015, 08:46:01 PM

detroit_johnny

I've got an idea to use one of my 3-button SwitchMote's with Felix's Home Automation system to display my garage door status; red LED lit if the door is up and green LED if the door is closed.  The button could be a toggle to command the door to go up or down (I am using modified garageMote code for my garage door, it uses an ultrasonic sensor on the ceiling to detect either garage open, closed with no car, or closed with a car present).  Not sure how to program the line or lines of code that would be needed in the metrics.js file events section. 

I'm having problems in the latest v6 version of the system to send manual console commands to the SwitchMote as well.  It's not responding at all when I put the node ID in and then use commands like B0:1 and B0:0 to try and manually toggle the switch status LED's. 

Felix

It's actually BTN1:1 and BTN1:0, cross reference in metrics.js when in doubt.
You can definitely do some scripting and make your SwitchMote play with your GarageMote.

detroit_johnny

Oh darn it, I missed that Felix, I was looking at the console status reports and got the idea it was B1 and not BTN1.  Works just fine!

I'll experiment now with the metrics.js file and report my findings.  This is fun, if I don't shoot myself in the foot!    :)  Thanks for the quick feedback!

detroit_johnny

Got it working!  Have not programmed the button function on the SwitchMote yet, but the garageMote and SwitchMote are "talking" to each other now via the gateway.  Red LED comes on when the door is up; Green LED comes on when the door is closed.

Here are the lines I added to the metrics.js file for setting up these events:
  garageOpen33open : { label:'GarageOpen: SM69 B0 red', icon:'action', descr:'Turn SwitchMote:69 BTN0 turns LED red when garage door node 33 is opened', serverExecute:function(node) { if (node.metrics['Status'] && node.metrics['Status'].value == 'OPEN' && (Date.now() - new Date(node.metrics['Status'].updated).getTime() < 2000)) { sendMessageToNode({nodeId:69, action:'BTN0:0'}); }; } },
  garageOpen33car : { label:'GarageClosed: SM69 B0 green with car', icon:'action', descr:'Turn SwitchMote:69 BTN0 turns LED green when garage door node 33 is closed with car present', serverExecute:function(node) { if (node.metrics['Status'] && node.metrics['Status'].value == 'CAR' && (Date.now() - new Date(node.metrics['Status'].updated).getTime() < 2000)) { sendMessageToNode({nodeId:69, action:'BTN0:1'}); }; } },
  garageOpen33closed : { label:'GarageClosed: SM69 B0 green without car', icon:'action', descr:'Turn SwitchMote:69 BTN0 turns LED green when garage door node 33 is closed without car present', serverExecute:function(node) { if (node.metrics['Status'] && node.metrics['Status'].value == 'CLOSED' && (Date.now() - new Date(node.metrics['Status'].updated).getTime() < 2000)) { sendMessageToNode({nodeId:69, action:'BTN0:1'}); }; } },


Thanks for your help Felix.  Will post more once I figure out the button toggle part.  I'm calling it a day for now.  Cheers!   :D

Felix

Nice work, yes you could have the SwitchMote talk to the GarageMote independently, or you could have the gateway broker that action the same way you had the buttons updated. When the button is pressed, send a message to the GarageMote node.
Of course if you choose to do this at the SwitchMote level (in SwitchMote sketch code) you have more control over the behavior of the hardware, and you could do things like blink an LED when a certain status is in progress (ie blink green when door opens and blink red when door closes). Lots of options and the fancier you go the more complex code gets but its doable if you really want it.