element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Upcycle It
  • Challenges & Projects
  • Design Challenges
  • Upcycle It
  • More
  • Cancel
Upcycle It
Blog PDU #12-2 - Better Together  [Upcycle It Challenge]
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: jasonwier92
  • Date Created: 23 May 2017 8:59 PM Date Created
  • Views 665 views
  • Likes 4 likes
  • Comments 3 comments
  • upcycle_it
  • home assistant
  • upcycled_pdu
Related
Recommended

PDU #12-2 - Better Together  [Upcycle It Challenge]

jasonwier92
jasonwier92
23 May 2017

What 12-2? Like what am I thinking, I know.  If you read my PDU #12 write up and looked at the great comments, you would have noticed that Andy Workshopshed (DAB backed Andy up on this) suggested I do what I did in many functions in one.  Well, at first I thought it was not going to work because the source does not come through, but then I got thinking, what if I could. But if the community can help me make my project better I should try. 

 

I looked at the output of the RBE node message, not just the payload, but the message. Here is what I got:

 

image

 

I get a topic that is the GPIO port that is being used.  So I can write a function.  Now how do I update all of these functions into one.  Well, here is what it looks like:

 

image

 

 

That WS Payload 1 was an old name, now I need to call it "Big Daddy" as it does it all.  Notice there are 10 output.  Eight of them are for MQTT messages and one for WS and MongoDB update.  Both WS and Mongo do JSON messages.  One thing I need to look into is that the MQTT messages could be JSON and how to make Home Assistant handle JSON in MQTT for a switch.  They have that for lights and I use it for RGB lights, but I have not tried for a switch (outlet) yet.

 

So what does BIG DADDY look like?

 

var GPIO = msg.topic;


// State Set
var WSstate = "off";
var DBstate = "off";
var MQTTstate = "OFF"
if (msg.payload == "1") {
    WSstate = "on";
    DBstate = "on";
    MQTTstate = "ON";
}


// Control Set
var control = "";
if (GPIO == "GP45") {
    control = "outlet1";
}
if (GPIO == "GP47") {
    control = "outlet2";
}
if (GPIO == "GP49") {
    control = "outlet3";
}
if (GPIO == "GP15") {
    control = "outlet4";
}
if (GPIO == "GP42") {
    control = "outlet5";   
}
if (GPIO == "GP84") {
    control = "outlet6";   
}
if (GPIO == "GP41") {
    control = "outlet7";    
}
if (GPIO == "GP78") {
    control = "outlet8";
}


var WSmsg = { payload: [
        {
            control: control,
            state: WSstate
        }
    ]
};


var MQTTmsg = { payload: MQTTstate };


var DBmsg = {
    query: { 
        device: "tower00", 
        control: control
    },
    payload: { 
        device: "tower00", 
        control: control,
        state: DBstate
    }
};

// Return values now!
if (GPIO == "GP45") {
    return [MQTTmsg,null,null,null,null,null,null,null,WSmsg,DBmsg];
}
if (GPIO == "GP47") {
    return [null,MQTTmsg,null,null,null,null,null,null,WSmsg,DBmsg];
}
if (GPIO == "GP49") {
    return [null,null,MQTTmsg,null,null,null,null,null,WSmsg,DBmsg];
}
if (GPIO == "GP15") {
    return [null,null,null,MQTTmsg,null,null,null,null,WSmsg,DBmsg];
}
if (GPIO == "GP42") {
    return [null,null,null,null,MQTTmsg,null,null,null,WSmsg,DBmsg];
}
if (GPIO == "GP84") {
    return [null,null,null,null,null,MQTTmsg,null,null,WSmsg,DBmsg];
}
if (GPIO == "GP41") {
    return [null,null,null,null,null,null,MQTTmsg,null,WSmsg,DBmsg];
}
if (GPIO == "GP78") {
    return [null,null,null,null,null,null,null,MQTTmsg,WSmsg,DBmsg];
}

 

 

TODO

  • Consolidate other functions like this one in my other flow, if I can.  That one would have to take MQTT and WS messages and put them into one function.
  • See if Home Assistant will accept JSON MQTT message for a switch.

 

Conclusion

Community ROCKS! Thank you Andy and DAB for pushing me.

  • Sign in to reply

Top Comments

  • Workshopshed
    Workshopshed over 8 years ago in reply to mcb1 +2
    I've definitely got some good ideas from the comments and writing can help with the planning. I have been using the blogs to keep the links I've found along the way hence the reference section on each…
  • DAB
    DAB over 8 years ago +2
    I spent a lot of time working on projects where my job was to assess each stage and identify issues before they became problems. So all of you get the benefit of my experiences. My physical limitations…
  • mcb1
    mcb1 over 8 years ago +1
    If you read my PDU #12 write up and looked at the great comments Strangely some members of the community complained about the blogging requirements, suggesting they were a waste of time. This feedback…
  • DAB
    DAB over 8 years ago

    I spent a lot of time working on projects where my job was to assess each stage and identify issues before they became problems.

     

    So all of you get the benefit of my experiences.

     

    My physical limitations prevent me from participating in these challenges, but I get to live the experience through those of you who do participate.

     

    If I can help just one challenger to get better, then I am very satisfied that I was able to help someone.

     

    Hopefully your experience will convince more members to participate now that they know that help is just a post away.

     

    DAB

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Workshopshed
    Workshopshed over 8 years ago in reply to mcb1

    I've definitely got some good ideas from the comments and writing can help with the planning.

    I have been using the blogs to keep the links I've found along the way hence the reference section on each post. So, I'd recommend keeping a journal on a long project even if you don't blog publicly

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 8 years ago

    If you read my PDU #12 write up and looked at the great comments

    Strangely some members of the community complained about the blogging requirements, suggesting they were a waste of time.

     

    This feedback is what we found useful during previous challenges, others will offer advice that may help.

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube