Dashboard 2 read incoming msg

Getting close to the end but missing how to set an incoming msg. In my example I have three buttons and when I press one the others grey out and the one turns green. Pressing any other one works the same. What I want to do is set one to green on power up. Can't seem to get that piece working. Found some code from @buckskin that I modified but obviously missing a piece.

<template>
    <v-app>
        <div class="justify-center ma-4">
            <v-card class="a2" width="100%" outlined>
                <v-card-title class="a1" :class="justify-center">{{msg.payload}}</v-card-title>
                <v-card-actions>
                    <v-btn class="btnBasic" :class="btnClass2" stacked @click="Power_Off">
                        <v-icon class="iconBasic" ref="icon1">{{icon1}}</v-icon>{{msg.payload1}}
                    </v-btn>

                    <v-btn class="btnBasic" :class="btnClass2" stacked @click="Power_On">
                        <v-icon class="iconBasic" ref="icon2">{{icon2}}</v-icon>Power On
                    </v-btn>

                    <v-btn class="btnBasic" :class="btnClass2" stacked @click="Power_Next">
                        <v-icon class="iconBasic" ref="icon3">{{icon3}}</v-icon>Power Never
                    </v-btn>
                </v-card-actions>
            </v-card>
        </div>
    </v-app>
</template>
<script>
    export default {
    data() {
        return {
            value: "OFF",
            icon1: "mdi-bed",
			icon2: "mdi-cog",
			icon3: "mdi-abacus",
        };
    },
    
    watch: {
      msg: function(){
          if (msg.payload == "start") {                  
            this.icon1 = "mdi-cog";
            this.$refs.icon1.$el.style.color = 'green';
            this.$refs.icon1.$el.style.textShadow = '0px 0px 10px #BD9608';
            this.$refs.icon2.$el.style.color = 'grey';
            this.$refs.icon2.$el.style.textShadow = '0px 0px 10px #BD9608';
            this.$refs.icon3.$el.style.color = 'grey';
            this.$refs.icon3.$el.style.textShadow = '0px 0px 10px #BD9608';	
          }
      }
    },
  
    methods: {
        Power_Off: function () {
            this.icon1 = "mdi-cog";
            this.$refs.icon1.$el.style.color = 'green';
            this.$refs.icon1.$el.style.textShadow = '0px 0px 10px #BD9608';
            this.$refs.icon2.$el.style.color = 'grey';
            this.$refs.icon2.$el.style.textShadow = '0px 0px 10px #BD9608';
            this.$refs.icon3.$el.style.color = 'grey';
            this.$refs.icon3.$el.style.textShadow = '0px 0px 10px #BD9608';				
            this.send({topic: "Power", payload:"Off"});   
        },
			
		Power_On: function () {
            this.icon1 = "mdi-bed";
            this.$refs.icon1.$el.style.color = 'grey';
            this.$refs.icon1.$el.style.textShadow = '0px 0px 10px #BD9608';
            this.$refs.icon2.$el.style.color = 'green';
            this.$refs.icon2.$el.style.textShadow = '0px 0px 10px #BD9608';
            this.$refs.icon3.$el.style.color = 'grey';
            this.$refs.icon3.$el.style.textShadow = '0px 0px 10px #BD9608';				
            this.send({topic: "Power", payload:"On"});
            },
			
		Power_Next: function () {
            this.$refs.icon1.$el.style.color = 'grey';
            this.$refs.icon1.$el.style.textShadow = '0px 0px 10px #BD9608';
            this.$refs.icon2.$el.style.color = 'grey';
            this.$refs.icon2.$el.style.textShadow = '0px 0px 10px #BD9608';		
            this.$refs.icon3.$el.style.color = 'green';
            this.$refs.icon3.$el.style.textShadow = '0px 0px 10px #BD9608';					
            this.send({topic: "Power", payload:"On"});
            },
        
	
    },
}
</script>

<style scoped>
    .btnBasic {
        background-color: #4F4F4F;
        /* Very dark gray */
        color: white;
        border-radius: 8px;
        /*width: 75px !important;*/
        height: 100% !important;

    }

    .btnBasic1 {
        background-color: #4F4F4F;
        /* Very dark gray */
        color: green;
        border-radius: 8px;
        /*width: 75px !important;*/
        height: 100% !important;

    }

    .btnBasic :hover {
        background-color: blue;
        /* Very dark gray */
        color: red;
        border-radius: 8px;
        /*width: 75px !important;*/
        height: 100% !important;

    }

    .btnOn {
        color: green;
        /* Dark washed rose */

    }

    .btnOff {
        color: darkgrey;

    }

    .iconBasic {
        font-size: 45px;
        height: 100%;
        width: 45px;

    }

    .iconOn {
        color: red;
        text-shadow: 0px 0px 0px;
        ;

    }

    .iconOff {
        color: darkgrey;
        text-shadow: 0px 0px 0px;

    }


    .a1 {
        /*    background-color:red; */
        height: 50px;
        margin-bottom: 1px;
        font-size: 16px;
        background-color: #303030;
        color: white;
        text-align: center padding-bottom: 4px;
        border-bottom: 2px solid #DD7F00;

    }

    .a2 {
        background-color: black;
        height: 100%;
        margin-top: 1px;
        font-size: 60px;
        color: #D7DBDD;

    }

    .b1 {
        color: #6689A1;
        height: 25px;
        margin-bottom: 1px;
        font-size: 16px;
        padding-bottom: 4px;
        border-bottom: 2px solid #DD7F00;
    }

    .b2 {
        height: 100%;
        margin-top: 1px;
        font-size: 28px;
        color: #D7DBDD;
    }
</style>

Feel like I'm swimming in the deep end of the pool.
Any help appreciated,
Thanks

This topic may help Listen to input on dashboard 2 ui-template

I hate to be thick but as far as I can tell my code matches up with the example you pointed to, and it still doesn't recognize the msg. Tried several different iterations and nothing.

I am sure other here know more than me on the new dashboard2, but if you want me to look at it please supply an example flow with incoming message/s in a inject nodes, so we can test.

Chip component should do the thing you are trying to build from scratch.

Actually the item group so you can make it from whatever element makes you happy. Item group component — Vuetify

[{"id":"2f59c0483345c031","type":"tab","label":"Flow 3","disabled":false,"info":"","env":[]},{"id":"291e319c93a47f5f","type":"ui-template","z":"2f59c0483345c031","group":"3f92ba46ef371b51","page":"","ui":"","name":"Msg","order":0,"width":"4","height":"4","head":"","format":"<template>\n    <v-app>\n        <div class=\"justify-center ma-4\">\n            <v-card class=\"a2\" width=\"100%\" outlined>\n                <v-card-title class=\"a1\" :class=\"justify-center\">{{msg.payload}}</v-card-title>\n                <v-card-actions>\n                    <v-btn class=\"btnBasic\" :class=\"btnClass2\" stacked @click=\"Power_Off\">\n                        <v-icon class=\"iconBasic\" ref=\"icon1\">{{icon1}}</v-icon>{{msg.payload1}}\n                    </v-btn>\n\n                    <v-btn class=\"btnBasic\" :class=\"btnClass2\" stacked @click=\"Power_On\">\n                        <v-icon class=\"iconBasic\" ref=\"icon2\">{{icon2}}</v-icon>Power On\n                    </v-btn>\n\n                    <v-btn class=\"btnBasic\" :class=\"btnClass2\" stacked @click=\"Power_Next\">\n                        <v-icon class=\"iconBasic\" ref=\"icon3\">{{icon3}}</v-icon>Power Never\n                    </v-btn>\n                </v-card-actions>\n            </v-card>\n        </div>\n    </v-app>\n</template>\n<script>\n    export default {\n    data() {\n        return {\n            value: \"OFF\",\n            icon1: \"mdi-bed\",\n\t\t\ticon2: \"mdi-cog\",\n\t\t\ticon3: \"mdi-abacus\",\n        };\n    },\n    \n\t\n    watch: {\n      msg: function(){\n\t\t\tif (msg.payload === \"start\") {                  \n\t\t\tthis.send({topic: \"yes\", payload:\"yes\"});\n          }\n      }\n    },\n  \n    methods: {\n        Power_Off: function () {\n            this.icon1 = \"mdi-cog\";\n            this.$refs.icon1.$el.style.color = 'green';\n            this.$refs.icon1.$el.style.textShadow = '0px 0px 10px #BD9608';\n            this.$refs.icon2.$el.style.color = 'grey';\n            this.$refs.icon2.$el.style.textShadow = '0px 0px 10px #BD9608';\n            this.$refs.icon3.$el.style.color = 'grey';\n            this.$refs.icon3.$el.style.textShadow = '0px 0px 10px #BD9608';\t\t\t\t\n            this.send({topic: \"Power\", payload:\"Off\"});   \n        },\n\t\t\t\n\t\tPower_On: function () {\n            this.icon1 = \"mdi-bed\";\n            this.$refs.icon1.$el.style.color = 'grey';\n            this.$refs.icon1.$el.style.textShadow = '0px 0px 10px #BD9608';\n            this.$refs.icon2.$el.style.color = 'green';\n            this.$refs.icon2.$el.style.textShadow = '0px 0px 10px #BD9608';\n            this.$refs.icon3.$el.style.color = 'grey';\n            this.$refs.icon3.$el.style.textShadow = '0px 0px 10px #BD9608';\t\t\t\t\n            this.send({topic: \"Power\", payload:\"On\"});\n            },\n\t\t\t\n\t\tPower_Next: function () {\n            this.$refs.icon1.$el.style.color = 'grey';\n            this.$refs.icon1.$el.style.textShadow = '0px 0px 10px #BD9608';\n            this.$refs.icon2.$el.style.color = 'grey';\n            this.$refs.icon2.$el.style.textShadow = '0px 0px 10px #BD9608';\t\t\n            this.$refs.icon3.$el.style.color = 'green';\n            this.$refs.icon3.$el.style.textShadow = '0px 0px 10px #BD9608';\t\t\t\t\t\n            this.send({topic: \"Power\", payload:\"On\"});\n            },\n        \n\t\n    },\n}\n</script>\n\n<style scoped>\n    .btnBasic {\n        background-color: #4F4F4F;\n        /* Very dark gray */\n        color: white;\n        border-radius: 8px;\n        /*width: 75px !important;*/\n        height: 100% !important;\n\n    }\n\n    .btnBasic1 {\n        background-color: #4F4F4F;\n        /* Very dark gray */\n        color: green;\n        border-radius: 8px;\n        /*width: 75px !important;*/\n        height: 100% !important;\n\n    }\n\n    .btnBasic :hover {\n        background-color: blue;\n        /* Very dark gray */\n        color: red;\n        border-radius: 8px;\n        /*width: 75px !important;*/\n        height: 100% !important;\n\n    }\n\n    .btnOn {\n        color: green;\n        /* Dark washed rose */\n\n    }\n\n    .btnOff {\n        color: darkgrey;\n\n    }\n\n    .iconBasic {\n        font-size: 45px;\n        height: 100%;\n        width: 45px;\n\n    }\n\n    .iconOn {\n        color: red;\n        text-shadow: 0px 0px 0px;\n        ;\n\n    }\n\n    .iconOff {\n        color: darkgrey;\n        text-shadow: 0px 0px 0px;\n\n    }\n\n\n    .a1 {\n        /*    background-color:red; */\n        height: 50px;\n        margin-bottom: 1px;\n        font-size: 16px;\n        background-color: #303030;\n        color: white;\n        text-align: center padding-bottom: 4px;\n        border-bottom: 2px solid #DD7F00;\n\n    }\n\n    .a2 {\n        background-color: black;\n        height: 100%;\n        margin-top: 1px;\n        font-size: 60px;\n        color: #D7DBDD;\n\n    }\n\n    .b1 {\n        color: #6689A1;\n        height: 25px;\n        margin-bottom: 1px;\n        font-size: 16px;\n        padding-bottom: 4px;\n        border-bottom: 2px solid #DD7F00;\n    }\n\n    .b2 {\n        height: 100%;\n        margin-top: 1px;\n        font-size: 28px;\n        color: #D7DBDD;\n    }\n</style>","storeOutMessages":true,"passthru":false,"resendOnRefresh":true,"templateScope":"local","className":"Test","x":610,"y":180,"wires":[["a4e53bec1f782057"]]},{"id":"a4e53bec1f782057","type":"debug","z":"2f59c0483345c031","name":"debug 51","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":780,"y":180,"wires":[]},{"id":"671418cf7289a1fb","type":"inject","z":"2f59c0483345c031","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"2","topic":"","payload":"Test input","payloadType":"str","x":220,"y":120,"wires":[["82ad0a9bf30def99"]]},{"id":"82ad0a9bf30def99","type":"function","z":"2f59c0483345c031","name":"function 7","func":"msg = {};\n\nmsg = {\n    payload1: \"Payload 1\",\n    payload: \"Master Power\",\n}\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":180,"wires":[["291e319c93a47f5f"]]},{"id":"57a8f22102f83c8b","type":"inject","z":"2f59c0483345c031","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"start","payloadType":"str","x":410,"y":240,"wires":[["291e319c93a47f5f"]]},{"id":"de38514824f4ea8e","type":"debug","z":"2f59c0483345c031","name":"debug 52","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":600,"y":260,"wires":[]},{"id":"3f92ba46ef371b51","type":"ui-group","name":"Msg","page":"532c4e3472d8f695","width":"6","height":"4","order":-1,"showTitle":false,"className":"","visible":"true","disabled":"false"},{"id":"532c4e3472d8f695","type":"ui-page","name":"Msg","ui":"2a155b07d50eeba0","path":"/page6","icon":"home","layout":"grid","theme":"a965ccfef139317a","order":6,"className":"","visible":"true","disabled":"false"},{"id":"2a155b07d50eeba0","type":"ui-base","name":"Page1","path":"/dashboard","includeClientData":true,"acceptsClientConfig":["ui-notification","ui-control"],"showPathInSidebar":false},{"id":"a965ccfef139317a","type":"ui-theme","name":"Default","colors":{"surface":"#404040","primary":"#109fbc","bgPage":"#e8e8e8","groupBg":"#d6d6d6","groupOutline":"#6fbc10"},"sizes":{"pagePadding":"12px","groupGap":"12px","groupBorderRadius":"4px","widgetGap":"12px"}}]

When debugging scripts it can be useful to use console.log() in the script. That will output to the console in the browser developer tools.

I have spent many hours looking at the web developer tools for various things and frankly all that does is confuse me. There's a ton of stuff in there I simply can't get my brain to parse.

Thanks @nipi I will certainly look at this. I'm afraid there are probably lots of things I do the hard way simply due to my limited knowledge.

Limited or not components make your life easier cos they work and they are documented.

You have vuetify examples and already many examples how it should live in db2 world. Your work is to combine those and modify by your needs.

Of course it's fun to create all from scratch. But I see you are losing fun already. Thus it helps if you get some results in between and if you then feel better it's time again maybe dive in deeper and make something unique.

I'm not certain I understand what you want but I'm assuming that you want to inject a start payload and have the Power_On called.

[{"id":"291e319c93a47f5f","type":"ui-template","z":"2f59c0483345c031","group":"","page":"69899b9aa555c7ec","ui":"","name":"Msg","order":0,"width":"0","height":"0","head":"","format":"<template>\n  <v-app>\n    <div class=\"justify-center ma-4\">\n      <v-card class=\"a2\" width=\"100%\" outlined>\n        <v-card-title class=\"a1\" :class=\"justify-center\"\n          >{{msg.payload}}</v-card-title\n        >\n        <v-card-actions>\n          <v-btn class=\"btnBasic\" :class=\"btnClass2\" stacked @click=\"Power_Off\">\n            <v-icon class=\"iconBasic\" ref=\"icon1\">{{icon1}}</v-icon\n            >{{msg.payload1}}\n          </v-btn>\n\n          <v-btn class=\"btnBasic\" :class=\"btnClass2\" stacked @click=\"Power_On\">\n            <v-icon class=\"iconBasic\" ref=\"icon2\">{{icon2}}</v-icon>Power On\n          </v-btn>\n\n          <v-btn\n            class=\"btnBasic\"\n            :class=\"btnClass2\"\n            stacked\n            @click=\"Power_Next\"\n          >\n            <v-icon class=\"iconBasic\" ref=\"icon3\">{{icon3}}</v-icon>Power Never\n          </v-btn>\n        </v-card-actions>\n      </v-card>\n    </div>\n  </v-app>\n</template>\n<script>\n  export default {\n    data() {\n      return {\n        value: 'OFF',\n        icon1: 'mdi-bed',\n        icon2: 'mdi-cog',\n        icon3: 'mdi-abacus',\n      }\n    },\n\n    watch: {\n      msg: {\n        deep: true,\n        handler(newVal) {\n          if (newVal.payload === 'start') {\n            this.Power_On()\n          }\n        },\n      },\n    },\n\n    methods: {\n      Power_Off: function () {\n        this.icon1 = 'mdi-cog'\n        this.$refs.icon1.$el.style.color = 'green'\n        this.$refs.icon1.$el.style.textShadow = '0px 0px 10px #BD9608'\n        this.$refs.icon2.$el.style.color = 'grey'\n        this.$refs.icon2.$el.style.textShadow = '0px 0px 10px #BD9608'\n        this.$refs.icon3.$el.style.color = 'grey'\n        this.$refs.icon3.$el.style.textShadow = '0px 0px 10px #BD9608'\n        this.send({ topic: 'Power', payload: 'Off' })\n      },\n\n      Power_On: function () {\n        this.icon1 = 'mdi-bed'\n        this.$refs.icon1.$el.style.color = 'grey'\n        this.$refs.icon1.$el.style.textShadow = '0px 0px 10px #BD9608'\n        this.$refs.icon2.$el.style.color = 'green'\n        this.$refs.icon2.$el.style.textShadow = '0px 0px 10px #BD9608'\n        this.$refs.icon3.$el.style.color = 'grey'\n        this.$refs.icon3.$el.style.textShadow = '0px 0px 10px #BD9608'\n        this.send({ topic: 'Power', payload: 'On' })\n      },\n\n      Power_Next: function () {\n        this.$refs.icon1.$el.style.color = 'grey'\n        this.$refs.icon1.$el.style.textShadow = '0px 0px 10px #BD9608'\n        this.$refs.icon2.$el.style.color = 'grey'\n        this.$refs.icon2.$el.style.textShadow = '0px 0px 10px #BD9608'\n        this.$refs.icon3.$el.style.color = 'green'\n        this.$refs.icon3.$el.style.textShadow = '0px 0px 10px #BD9608'\n        this.send({ topic: 'Power', payload: 'On' })\n      },\n    },\n  }\n</script>\n\n<style scoped>\n  .btnBasic {\n      background-color: #4F4F4F;\n      /* Very dark gray */\n      color: white;\n      border-radius: 8px;\n      /*width: 75px !important;*/\n      height: 100% !important;\n\n  }\n\n  .btnBasic1 {\n      background-color: #4F4F4F;\n      /* Very dark gray */\n      color: green;\n      border-radius: 8px;\n      /*width: 75px !important;*/\n      height: 100% !important;\n\n  }\n\n  .btnBasic :hover {\n      background-color: blue;\n      /* Very dark gray */\n      color: red;\n      border-radius: 8px;\n      /*width: 75px !important;*/\n      height: 100% !important;\n\n  }\n\n  .btnOn {\n      color: green;\n      /* Dark washed rose */\n\n  }\n\n  .btnOff {\n      color: darkgrey;\n\n  }\n\n  .iconBasic {\n      font-size: 45px;\n      height: 100%;\n      width: 45px;\n\n  }\n\n  .iconOn {\n      color: red;\n      text-shadow: 0px 0px 0px;\n      ;\n\n  }\n\n  .iconOff {\n      color: darkgrey;\n      text-shadow: 0px 0px 0px;\n\n  }\n\n\n  .a1 {\n      /*    background-color:red; */\n      height: 50px;\n      margin-bottom: 1px;\n      font-size: 16px;\n      background-color: #303030;\n      color: white;\n      text-align: center padding-bottom: 4px;\n      border-bottom: 2px solid #DD7F00;\n\n  }\n\n  .a2 {\n      background-color: black;\n      height: 100%;\n      margin-top: 1px;\n      font-size: 60px;\n      color: #D7DBDD;\n\n  }\n\n  .b1 {\n      color: #6689A1;\n      height: 25px;\n      margin-bottom: 1px;\n      font-size: 16px;\n      padding-bottom: 4px;\n      border-bottom: 2px solid #DD7F00;\n  }\n\n  .b2 {\n      height: 100%;\n      margin-top: 1px;\n      font-size: 28px;\n      color: #D7DBDD;\n  }\n</style>\n","storeOutMessages":true,"passthru":false,"resendOnRefresh":true,"templateScope":"widget:page","className":"Test","x":610,"y":180,"wires":[["a4e53bec1f782057"]]},{"id":"a4e53bec1f782057","type":"debug","z":"2f59c0483345c031","name":"debug 51","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":740,"y":180,"wires":[]},{"id":"57a8f22102f83c8b","type":"inject","z":"2f59c0483345c031","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"start","payloadType":"str","x":490,"y":180,"wires":[["291e319c93a47f5f"]]},{"id":"69899b9aa555c7ec","type":"ui-page","name":"Projects","ui":"22e2f5c865718f73","path":"/page1","icon":"home","layout":"grid","theme":"c7c753dd7138d5cc","order":-1,"className":"","visible":"true","disabled":"false"},{"id":"22e2f5c865718f73","type":"ui-base","name":"Kimchi","path":"/dashboard","includeClientData":true,"acceptsClientConfig":["ui-notification","ui-control"],"showPathInSidebar":false},{"id":"c7c753dd7138d5cc","type":"ui-theme","name":"Kimchi Theme","colors":{"surface":"#ffffff","primary":"#077dab","bgPage":"#eeeeee","groupBg":"#ffffff","groupOutline":"#cccccc"},"sizes":{"pagePadding":"2px","groupGap":"0px","groupBorderRadius":"0px","widgetGap":"0px"}}]

outstanding, thanks

1 Like

so here is an interesting side effect. Before I put the new code in when I press a button the icons change color and it output's a message which I can read in the debug node. With the addition of the code to read a message the icons do change color but I no longer get a message out of the node.
[edit]
so I took out the new code and it still doesn't send a message. It used to, I don't know what changed.

This is strange, shut down browser, rebooted everything seems to work

Yep. I get tripped up by that every hour or so.

Assuming your using Chrome, in the JavaScript Console, you can set what messages come through. If you turn off "info" you won't get an the stuff you don't need to see.
You'll just see errors and any output of console.log.
This is a really nice way to debug because it will tell you what's happening on the 'client side' (JavaScript/html/CSS) before it gets back to Node-RED.

So if it seems to be working in the console, then we know it's an issue outside of that (if the message is sent correctly), eg this.send yourBoundVariable.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.