Help how to change the icon depending on value

This is an extract from my code:

        if (pstate > 2) {
            msg2 = { payload: '<font color = "green"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "green" };
        }

Which works.

What I want to do is:
depending on another value, change the icon.

If istate == 0 then the icon would be something else.

To make it easier I've tried to make the icon part modular.

let icon1 = '<i class="fa fa fa-bullseye fa - 2x" >'
let icon2 = '<i class="material-icons" ><span> wifi</span>'

I'm not sure that is correct.
And that's why I'm asking for help.

This is a bigger extract of the code.

let icon1 = '<font color = "green"> <i class="fa fa-bullseye fa-2x" ></i></font>'
let icon2 = '<font color = "green"> <I class="material-icons"><span> wifi </span>'
if (istate === 0) {
    msg4 = { payload: '<font color = "red"> <i class="fa fa fa-bullseye fa-2x" ></i></font>', colour: "red" };
} else

    if (istate > 4) {
        msg4 = { payload: icon2, colour: "lime" };
    } else

        if (istate > 2) {
            msg4 = { payload: '<font color = "green"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "green" };
        } else

            if (istate == 1) {
                msg4 = { payload: '<font color = "springgreen"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "springgreen" };
            } else

                if (istate == "UNKNOWN") {
                    msg4 = { payload: '<font color = "black"> <i class="fa fa-question-circle fa-2x" ></i></font>', colour: "black" };
                }

if (debug == 1) {
    node.warn("end of internet")
}

And you can see how I tried on the line:
if (istate > 4)

It kind of works.

But I don't think the colour is being seen/translated/parsed.

Someone - please?

(Update)

This is the start of a better way but only implimented on the >4 line for now.

let icon1 = '<font color = "green"> <i class="fa fa-bullseye fa-2x" ></i></font>'
let icon2 = '<font color = "green"> <I class="material-icons"><span> wifi </span>'
let icon3
if (pstate == 0)
{
    icon3 = icon2
} else
{
    icon3 = icon1
}
if (istate === 0) {
    msg4 = { payload: '<font color = "red"> <i class="fa fa fa-bullseye fa-2x" ></i></font>', colour: "red" };
} else

    if (istate > 4) {
        msg4 = { payload: icon3, colour: "lime" };
    } else
(more code below and deleted for clarity)

(Sorry)

As font awesome has a wifi icon, I modified the code.

let icon1 = '<font color = "green"> <i class="fa fa-bullseye fa-2x" ></i></font>'
let icon2 = '<font color = "green"> <I class="fa fa-wifi fa-2x" ></i></font>'
let icon3
if (pstate == 0)
{
    icon3 = icon2
} else
{
    icon3 = icon1
}
if (istate === 0) {
    msg4 = { payload: '<font color = "red"> <i class="fa fa fa-bullseye fa-2x" ></i></font>', colour: "red" };
} else

    if (istate > 4) {
        msg4 = '{ payload:' + icon3 + ', colour: "lime" }';
    } else

But I am still not having any luck constructing the msg.payload.

This is the original node-red-dashboard not DB2?

What dashboard item are you sending the message to?

Sorry, it is the original DB.

And it is being sent to a text node.

Try this simple example for Dashboard-1...
monday_icon_switch

[{"id":"7085423bf8fdf2c0","type":"tab","label":"Switch icon on value","disabled":false,"info":"","env":[]},{"id":"inject","type":"inject","z":"7085423bf8fdf2c0","name":"Set Weather","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"cloudy","payloadType":"str","x":270,"y":240,"wires":[["ui_template"]]},{"id":"ui_template","type":"ui_template","z":"7085423bf8fdf2c0","group":"9fc89425.a32b58","name":"Icon Changer","order":1,"width":0,"height":0,"format":"<div style=\"text-align: center;\">\n    <i class=\"fa\" ng-class=\"{'fa-sun-o': msg.payload === 'sunny','fa-cloud': msg.payload === 'cloudy','fa-bolt': msg.payload === 'stormy'}\" style=\"font-size: 48px;\"></i>\n</div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","className":"","x":500,"y":240,"wires":[[]]},{"id":"9d92317ff7bd63d3","type":"inject","z":"7085423bf8fdf2c0","name":"Set Value 0 (Sunny)","props":[{"p":"payload","v":"0","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":270,"y":400,"wires":[["90a50158577da261"]]},{"id":"53231bf4c46c225e","type":"inject","z":"7085423bf8fdf2c0","name":"Set Value 1 (Cloudy)","props":[{"p":"payload","v":"1","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":270,"y":440,"wires":[["90a50158577da261"]]},{"id":"8714f4bfa063d86a","type":"inject","z":"7085423bf8fdf2c0","name":"Set Value 2 (Stormy)","props":[{"p":"payload","v":"2","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":270,"y":480,"wires":[["90a50158577da261"]]},{"id":"90a50158577da261","type":"ui_template","z":"7085423bf8fdf2c0","group":"9fc89425.a32b58","name":"Icon Changer","order":1,"width":0,"height":0,"format":"<div style=\"text-align: center;\">\n    <i class=\"fa\" ng-class=\"{'fa-sun-o': msg.payload === 0,'fa-cloud': msg.payload === 1,'fa-bolt': msg.payload === 2}\" style=\"font-size: 48px;\"></i>\n</div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","className":"","x":520,"y":440,"wires":[[]]},{"id":"e4b3b7acc35b434e","type":"comment","z":"7085423bf8fdf2c0","name":"Using textual-names to switch the icon","info":"","x":330,"y":200,"wires":[]},{"id":"973c8bb601581c94","type":"comment","z":"7085423bf8fdf2c0","name":"Using numerical-values to switch the icon","info":"","x":320,"y":360,"wires":[]},{"id":"9fc89425.a32b58","type":"ui_group","name":"System status","tab":"246a538c.3d84b4","order":2,"disp":true,"width":"4","collapse":false,"className":""},{"id":"246a538c.3d84b4","type":"ui_tab","name":"SMART Home - lighting","icon":"home","order":1,"disabled":false,"hidden":false}]

Using CSS in the ui-template like this...

<div style="text-align: center;">
    <i class="fa" ng-class="{
        'fa-sun-o': msg.payload === 'sunny',
        'fa-cloud': msg.payload === 'cloudy',
        'fa-bolt': msg.payload === 'stormy'
    }" style="font-size: 48px;"></i>
</div>

Or...

<div style="text-align: center;">
    <i class="fa" ng-class="{
        'fa-sun-o': msg.payload === 0,
        'fa-cloud': msg.payload === 1,
        'fa-bolt': msg.payload === 2
    }" style="font-size: 48px;"></i>
</div>

So if I understand correctly, your text node is displaying an icon but no other text?

Certainly one way is to use a template with CSS for the colour
image

Specify the class in the payload like this
<i class="fa fa fa-bullseye fa-2x red"></i>
or
<i class="fa fa-wifi fa-2x green" ></i>

Ok, I maybe didn't explain it as well as I should have.

There are 2 things at play here.

istate and internet

Depending on the value of internet it changes the colour of the icon.
That is working.

To complicate things, if istate == 0 then the icon is changed from fa-bullseye to fa-wifi.
Then depending on the value of internet the colour is set.

So I am trying to breakdown the structure of the message so I can edit the icon part/name.

But I lack the skills/knowledge to append the messages when I've broken it down into pieces.

So going back to my third post you can see how I've cheated with the icon.
I don't think that is too bad.
I have (since) tried to better optimise the code to include the {payload part
Test code below.


let icon1 = `'{ payload:<font color = "green"> <i class="fa fa-bullseye fa-2x" ></i></font>, colour: '`
let msg4 = icon1 + '"lime" }';

return msg4;

But when I run that I get:
Function tried to send a message of type string

And I suspect that is because the icon1 is not correctly parsed.
You can see I have tried to put the reverse apostrophe around it.
But that doesn't work either.

It is complicated for me as the text has both ' and " in it and I don't know how to encapsulate that all as one thing.

Does that help?

To me that is magic.

I see the code but I can't/don't understand just about all of it.

Yeah, shame on me.

I'm also sort of confused as - as much as it does allow icon change - is missing the colour.

That changes more than the icon.

I'm trying to understand it, but as I said: It is black magic to me.

And as I said to @dynamicdave I am missing something.

I have...... 5 (I think) colours and 2 icons.

I am foolishly trying to make the message in the function node and send it to a text node that displays the icon (at 2x size) with the given colour.

I'm not seeing anything I can use here.

I don't really understand the various inputs to decide which icon and which colour is used.
Please show us your complete function node.

It is long/convoluted but better than it was originally.

Understand it was made by me (the original) a LONG time ago.
The original didn't work.
Well, I THOUGHT it did, but time proved me wrong.
Problems were becoming annoying with false alarms/warnings.
So I stepped way back and tried to rewrite it in a better way.

The outputs are all sent to DB-1 (The original one) text nodes that simply show {{msg.payload}}

Where I am with this is starting at line 380
There are some attempts to change the icon (as earlier show) but they don't work.

//
//  Routines.
//
//Set Bit
function setBit(number, bitPosition) {
    return number | (1 << bitPosition);
}
//
//Clear Bit
function clearBit(number, bitPosition) {
    const mask = ~(1 << bitPosition);
    return number & mask;
}
//
/////////////////////////////////

if (msg.payload == "WIPE") {
    //
    context.set("rstate", 0)
    context.set("pstate", 0)
    context.set("mstate", 0)
    context.set("istate", 0)
    node.status({ text: "RESET" })
    return;
}

if (msg.payload == "DEBUG") {
    context.set("debug", msg.onoff);
    if (msg.onoff == 0) {
        node.status({});
        //        return;
    } else {
        node.status({ fill: "blue", text: "DEBUG ON" });
        //        return;
    }
    return;
}

let msg1 = {}   //  router
let msg2 = {}   //  pip
let msg3 = {}   //  Telstra modem
let msg4 = {}   //  internet

let debug = context.get("debug")

let sender = msg.payload.Who
let sender_i

let router = msg.payload.router
let pip = msg.payload.pip
let modem = msg.payload.modem
let internet = msg.payload.internet

if (debug == 1) {
    //
    node.warn("Who " + sender + " router " + router + " pip " + pip + " modem " + modem + " internet " + internet)
}

//      Edit in each machine so weights are correct
switch (sender) {
    case "BedPi":
        sender_i = 1
        break
    case "TelePi":
        sender_i = 2
        break
    case "TimePi":
        sender_i = 3
        break
}

//let router = msg.router
//let pip = msg.pip
//let modem = msg.modem
//let internet = msg.internet


let bit
let rstate = context.get("rstate") || 0
let pstate = context.get("pstate") || 0
let mstate = context.get("mstate") || 0
let istate = context.get("istate") || 0


//node.warn("Sender " + sender)
//node.warn("bit " + bit)
//node.warn("Router " + router)
//node.warn("PIP " + pip)
//node.warn("modem " + modem)
//node.warn("Internet " + internet)

//node.warn("rstate " + rstate)
//node.warn("pip " + pstate)
//node.warn("mstate " + mstate)
//node.warn("istate " + istate)


switch (sender_i) {
    case 1:
        bit = 0
        if (debug == 1) {
            node.warn("Bit " + bit)
        }
        //      Router
        if (router == "offline") {
            //
            //    node.warn("router off line")
            rstate = clearBit(rstate, bit)
            context.set("rstate", rstate)
        }
        if (router == "online") {
            //
            //    node.warn("router on line")
            rstate = setBit(rstate, bit)
            context.set("rstate", rstate)
        }
        //      Publib IP
        if (pip == "offline") {
            //
            //    node.warn("pip off line")
            pstate = clearBit(pstate, bit)
            context.set("pstate", pstate)
        }
        if (pip == "online") {
            //
            //    node.warn("pip on line")
            pstate = setBit(pstate, bit)
            context.set("pstate", pstate)
        }
        //      modem
        if (modem == "offline") {
            //
            //    node.warn("modem off line")
            mstate = clearBit(mstate, bit)
            context.set("mstate", mstate)
        }
        if (modem == "online") {
            //
            //    node.warn("modem on line")
            mstate = setBit(mstate, bit)
            context.set("mstate", mstate)
        }
        //      Internet IP
        if (internet == "offline") {
            //
            //    node.warn("internet off line")
            istate = clearBit(istate, bit)
            context.set("istate", istate)
        }
        if (internet == "online") {
            //
            //    node.warn("internet on line")
            istate = setBit(istate, bit)
            context.set("istate", istate)
        }
        node.status({ text: rstate + " " + pstate + " " + mstate + " " + istate })
        break
    case 2:
        bit = 1
        if (debug == 1) {
            node.warn("Bit " + bit)
        }
        //      Router
        if (router == "offline") {
            //
            //    node.warn("router off line")
            rstate = clearBit(rstate, bit)
            context.set("rstate", rstate)
        }
        if (router == "online") {
            //
            //    node.warn("router on line")
            rstate = setBit(rstate, bit)
            context.set("rstate", rstate)
        }
        //      Publib IP
        if (pip == "offline") {
            //
            //    node.warn("pip off line")
            pstate = clearBit(pstate, bit)
            context.set("pstate", pstate)
        }
        if (pip == "online") {
            //
            //    node.warn("pip on line")
            pstate = setBit(pstate, bit)
            context.set("pstate", pstate)
        }
        //      modem
        if (modem == "offline") {
            //
            //    node.warn("modem off line")
            mstate = clearBit(mstate, bit)
            context.set("mstate", mstate)
        }
        if (modem == "online") {
            //
            //    node.warn("modem on line")
            mstate = setBit(mstate, bit)
            context.set("mstate", mstate)
        }
        //      Internet IP
        if (internet == "offline") {
            //
            //    node.warn("internet off line")
            istate = clearBit(istate, bit)
            context.set("istate", istate)
        }
        if (internet == "online") {
            //
            //    node.warn("internet on line")
            istate = setBit(istate, bit)
            context.set("istate", istate)
        }
        //node.warn("End of TelePi")
        node.status({ text: rstate + " " + pstate + " " + mstate + " " + istate })
        break
    case 3:
        bit = 2
        if (debug == 1) {
            node.warn("Bit " + bit)
        }
        //      Router
        if (router == "offline") {
            //
            //    node.warn("router off line")
            rstate = clearBit(rstate, bit)
            context.set("rstate", rstate)
        }
        if (router == "online") {
            //
            //    node.warn("router on line")
            rstate = setBit(rstate, bit)
            context.set("rstate", rstate)
        }
        //      Publib IP
        if (pip == "offline") {
            //
            //    node.warn("pip off line")
            pstate = clearBit(pstate, bit)
            context.set("pstate", pstate)
        }
        if (pip == "online") {
            //
            //    node.warn("pip on line")
            pstate = setBit(pstate, bit)
            context.set("pstate", pstate)
        }
        //      modem
        if (modem == "offline") {
            //
            //    node.warn("modem off line")
            mstate = clearBit(mstate, bit)
            context.set("mstate", mstate)
        }
        if (modem == "online") {
            //
            //    node.warn("modem on line")
            mstate = setBit(mstate, bit)
            context.set("mstate", mstate)
        }
        //      Internet IP
        if (internet == "offline") {
            //
            //    node.warn("internet off line")
            istate = clearBit(istate, bit)
            context.set("istate", istate)
        }
        if (internet == "online") {
            //
            //    node.warn("internet on line")
            istate = setBit(istate, bit)
            context.set("istate", istate)
        }
        node.status({ text: rstate + " " + pstate + " " + mstate + " " + istate })
        break
}

if (debug == 1) {
    node.warn("here " + rstate + " " + pstate + " " + mstate + " " + istate)
}



//      ==============      ROUTER
if (rstate === 0) {
    if (debug == 1) {
        node.warn("rstate == 0")
    }
    mstate = "UNKNOWN";
    msg1 = { payload: '<font color = "red"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "black" };
    msg2 = { payload: '<font color = "red"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "black" };
    msg3 = { payload: '<font color = "red"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "black" };
    msg4 = { payload: '<font color = "red"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "black" };
} else

    if (rstate > 4) {
        //node.status({fill: "green",text:"machine1 (temp)"});
        if (debug == 1) {
            node.warn("rstate > 4")
        }
        msg1 = { payload: '<font color = "lime"> <i class="fa fa-bullseye fa-2x"></i></font>', colour: "lime" };
    } else

        if (rstate > 2) {
            if (debug == 1) {
                node.warn("rstate > 2")
            }
            //node.status({fill: "yellow",text:"machine2 (temp)"});
            msg1 = { payload: '<font color = "green"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "green" };
        } else

            if (rstate == 1) {
                if (debug == 1) {
                    node.warn("rstate == 1")
                }
                //node.status({fill: "red",text:"machine3 (temp)"});
                msg1 = { payload: '<font color = "springgreen"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "springgreen" };
            }

if (debug == 1) {
    node.warn("end of rstate")
}



//      ==============      Pulic IP
if (pstate === 0) {
    msg2 = { payload: '<font color = "red"> <i class="fa fa fa-bullseye fa-2x" ></i></font>', colour: "red" };
} else

    if (pstate > 4) {
        msg2 = { payload: '<font color = "lime"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "lime" };
    } else

        if (pstate > 2) {
            msg2 = { payload: '<font color = "green"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "green" };
        } else

            if (pstate == 1) {
                msg2 = { payload: '<font color = "springgreen"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "springgreen" };
            } else

                if (pstate == "UNKNOWN") {
                    msg2 = { payload: '<font color = "black"> <i class="fa fa-question-circle fa-2x" ></i></font>', colour: "black" };
                }

if (debug == 1) {
    node.warn("end of pstate")
}


//      ==============      Telstra modem
if (mstate === 0) {
    msg3 = { payload: '<font color = "red"> <i class="fa fa fa-bullseye fa-2x" ></i></font>', colour: "red" };
} else

    if (mstate > 4) {
        msg3 = { payload: '<font color = "lime"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "lime" };
    } else

        if (mstate > 2) {
            msg3 = { payload: '<font color = "green"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "green" };
        } else

            if (mstate == 1) {
                msg3 = { payload: '<font color = "springgreen"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "springgreen" };
            } else

                if (mstate == "UNKNOWN") {
                    msg3 = { payload: '<font color = "black"> <i class="fa fa-question-circle fa-2x" ></i></font>', colour: "black" };
                }

if (debug == 1) {
    node.warn("end of mstate")
}


//      ==============      Internet IP
let icon1 = '<font color = "green"> <i class="fa fa-bullseye fa-2x" ></i></font>'
let icon2 = '<font color = "green"> <I class="material-icons"><span> wifi </span>'
let icon3
if (pstate == 0)
{
    icon3 = icon2
} else
{
    icon3 = icon1
}
if (istate === 0) {
    msg4 = { payload: '<font color = "red"> <i class="fa fa fa-bullseye fa-2x" ></i></font>', colour: "red" };
} else

    if (istate > 4) {
        msg4 = { payload:'<font color = "lime"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "lime" };
    } else

        if (istate > 2) {
            msg4 = { payload: '<font color = "green"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "green" };
        } else

            if (istate == 1) {
                msg4 = { payload: '<font color = "springgreen"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "springgreen" };
            } else

                if (istate == "UNKNOWN") {
                    msg4 = { payload: '<font color = "black"> <i class="fa fa-question-circle fa-2x" ></i></font>', colour: "black" };
                }

if (debug == 1) {
    node.warn("end of internet")
}


return [msg1, msg2, msg3, msg4]

Try this flow that sends msg.color as well as msg.payload so you can change the 'shape' and 'color' attributes independently. Sorry - I haven't got time to wade through your lengthy flow.
monday_icon_switch_v2

[{"id":"71905ebda8df3d6f","type":"tab","label":"Flow 10","disabled":false,"info":"","env":[]},{"id":"74f68d2305e2ab74","type":"inject","z":"71905ebda8df3d6f","name":"Set Shape (Sunny) & Color (Red)","props":[{"p":"payload"},{"p":"color","v":"red","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":280,"y":120,"wires":[["7f943e57c473530c"]]},{"id":"afa542e24f4d4b8d","type":"inject","z":"71905ebda8df3d6f","name":"Set Shape (Cloudy) & Color (Blue)","props":[{"p":"payload","v":"1","vt":"num"},{"p":"color","v":"blue","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":280,"y":160,"wires":[["7f943e57c473530c"]]},{"id":"40fa421e266c953e","type":"inject","z":"71905ebda8df3d6f","name":"Set Shape (Stormy) & Color (Yellow)","props":[{"p":"payload","v":"2","vt":"num"},{"p":"color","v":"yellow","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":280,"y":200,"wires":[["7f943e57c473530c"]]},{"id":"7f943e57c473530c","type":"ui_template","z":"71905ebda8df3d6f","group":"9fc89425.a32b58","name":"Icon Changer","order":1,"width":0,"height":0,"format":"<div style=\"text-align: center;\">\n    <i class=\"fa\" ng-class=\"{'fa-sun-o': msg.payload === 0,'fa-cloud': msg.payload === 1,'fa-bolt': msg.payload === 2}\" \n    style=\"color: {{msg.color || 'black'}}; font-size: 48px;\"></i>\n</div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","className":"","x":560,"y":160,"wires":[[]]},{"id":"9fc89425.a32b58","type":"ui_group","name":"System status","tab":"246a538c.3d84b4","order":2,"disp":true,"width":"4","collapse":false,"className":""},{"id":"246a538c.3d84b4","type":"ui_tab","name":"SMART Home - lighting","icon":"home","order":1,"disabled":false,"hidden":false}]

OK that is certainly quite long and convoluted.

HTML syntax
I have convinced myself with this little function that [some of] your HTML syntax works. The text field does change to a green bullseye icon:

msg.payload = "<font color='springgreen'> <i class='fa fa-bullseye fa-2x' ></i></font>"
return msg;

Syntax error
There is at least one error in your HTML code though:

//      ==============      Internet IP
let icon1 = '<font color = "green"> <i class="fa fa-bullseye fa-2x" ></i></font>'
let icon2 = '<font color = "green"> <I class="material-icons"><span> wifi </span>'

I don't think the capital <I ... for icon2 is a problem, but you don't have a closing </i> tag.
I think it should be

let icon2 = '<font color = "green"> <I class="material-icons"><span> wifi </span></i>'

msg.colour
And unless I misunderstand, appending msg.colour to your output messages serves no purpose. I think you could omit colour: "green" in many lines.

msg1 = { payload: '<font color = "green"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "green" };

An alternative approach
If I was writing this, I would try to minimise HTML errors by having as few lines as possible that compose HTML. Something like in this (greatly simplified) example. But that would be a complete rewrite.

[{"id":"135845945e04e7b7","type":"inject","z":"93cb71efa2c3321f","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":210,"y":260,"wires":[["c5aaf4a0153df8ef"]]},{"id":"c5aaf4a0153df8ef","type":"function","z":"93cb71efa2c3321f","name":"function 66","func":"let msg1 = {}\nlet msg2 = {}\nlet colour1\nlet icon1\nlet text1\nlet colour2\nlet icon2\nlet text2\n\n// complicated processing here that sets colour1, icon1, text1 etc\ncolour1 = \"red\"\nif (msg.payload === true) {\n    icon1 = \"fa-wifi\"\n    text1 = \"\"\n}\nelse {\n    colour1 = \"green\"\n    icon1 = \"fa-bullseye\"\n    text1 = \"Some text\"\n}\n// More complicated code to set colour2, icon2 and text 2\ncolour2 = \"blue\"\nicon2 = \"fa-envelope-open\"\ntext2 = \"\"\n\nmsg1.payload = '<font color = \"' + colour1 + '\"> <i class=\"fa ' + icon1 + ' fa-2x\" ><span> ' + text1 + ' </span></i></font>'\nmsg2.payload = '<font color = \"' + colour2 + '\"> <i class=\"fa ' + icon2 + ' fa-2x\" ><span> ' + text2 + ' </span></i></font>'\nreturn [msg1, msg2]","outputs":2,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":280,"wires":[["6807ad8f039c5af5","c7fa5c1a5f483de1"],["1f59e1001a14fc0d","5fdb29cefebeb2d2"]]},{"id":"ba649785d332c83c","type":"inject","z":"93cb71efa2c3321f","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":210,"y":300,"wires":[["c5aaf4a0153df8ef"]]},{"id":"6807ad8f039c5af5","type":"ui_text","z":"93cb71efa2c3321f","group":"5b5ee9f169c93ecf","order":0,"width":0,"height":0,"name":"","label":"test1","format":"{{msg.payload}}","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#0000ff","x":570,"y":260,"wires":[]},{"id":"1f59e1001a14fc0d","type":"ui_text","z":"93cb71efa2c3321f","group":"5b5ee9f169c93ecf","order":0,"width":0,"height":0,"name":"","label":"test2","format":"{{msg.payload}}","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#0000ff","x":570,"y":300,"wires":[]},{"id":"5fdb29cefebeb2d2","type":"debug","z":"93cb71efa2c3321f","name":"debug2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":580,"y":340,"wires":[]},{"id":"c7fa5c1a5f483de1","type":"debug","z":"93cb71efa2c3321f","name":"debug1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":580,"y":220,"wires":[]},{"id":"5b5ee9f169c93ecf","type":"ui_group","name":"demo","tab":"195948bb680041dd","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"195948bb680041dd","type":"ui_tab","name":"Demo","icon":"dashboard","disabled":false,"hidden":false}]
1 Like

I added the msg.colour for testing.
I stuck a function node that did a node.status({}) with the colour so I could see it working from the editor screen.

Thanks for the catch on the <I. That's me not releasing the shift key quick enough.

Thanks both.
@dynamicdave
I do see what you are doing and I hope to one day understand it better.
For now I need to build my confidence on what I do no and (I think) not play too much in stuff I don't.

@jbudd
payload = '<font color = "' + colour1 + '"> <i class="fa ' + icon1 + ' fa-2x" ><span> ' + text1 + ' </span></i></font>'
is where I was stuck.

That is the structure I was wanting to use.

Taking all you said about optimising,
I think there is/are about 21 lines which are like that.

So ideally I could parse the value and set the colour and reduce the 21 down to ..... about 9
I'll start on that shortly and see what happens.

Again thanks to you both.

Ummm...

Good news.

Bad news.

I tested the code and it seems to work.

(test flow)

[{"id":"e734dddc56ea88fe","type":"debug","z":"ed217a75.2f6d9","name":"debug 3452","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2880,"y":1550,"wires":[]},{"id":"ea31d712161ee752","type":"inject","z":"ed217a75.2f6d9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":2390,"y":1260,"wires":[["d7d9edd1bf88aba5"]]},{"id":"5ca7e93d114ba4bb","type":"inject","z":"ed217a75.2f6d9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":2390,"y":1300,"wires":[["d7d9edd1bf88aba5"]]},{"id":"2ad160e86af333b4","type":"inject","z":"ed217a75.2f6d9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":2390,"y":1340,"wires":[["d7d9edd1bf88aba5"]]},{"id":"9ff1ab03f2881e9a","type":"inject","z":"ed217a75.2f6d9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"5","payloadType":"num","x":2390,"y":1380,"wires":[["d7d9edd1bf88aba5"]]},{"id":"d7d9edd1bf88aba5","type":"function","z":"ed217a75.2f6d9","name":"function 180","func":"/////////////////////////////////////\n//  getColour\nfunction getColour(number) {\n    let colour; // Declare the variable\n\n    if (number > 4) {\n        colour = \"lime\";\n    } else if (number > 1) {\n        colour = \"green\";\n    } else if (number === 1) {\n        colour = \"springgreen\";\n    } else if (number === 0) {\n        colour = \"red\";\n    }\n\n    return colour; // Return the colour\n}\n/////////////////////////////////////\n\nlet colour\n\n\nlet number = msg.payload\ncolour = getColour(number)\nlet icon = \"fa-bullseye\"\n\nmsg.payload = '<font color = \"' + colour + '\"> <i class=\"fa ' + icon + ' fa-2x\" ></i></font>'\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2600,"y":1340,"wires":[["e734dddc56ea88fe"]]}]

As you increase the value, the colours change.
(Alas I didn't check them all, and while I'm typing this I fear that may be a problem)

But when I move that to my node - replacing a lot of lines with few.....
It fails.

Extract from the node now.

//  getColour
function getColour(number) {
    let colour; // Declare the variable

    if (number > 4) {
        colour = "lime";
    } else if (number > 1) {
        colour = "green";
    } else if (number === 1) {
        colour = "springgreen";
    } else if (number === 0) {
        colour = "red";
    }

    return colour; // Return the colour
}
//
let colour
let icon
//      ==============      ROUTER

colour = getColour(rstate)
icon = "fa-bullseye"

msg1.payload = '<font color = "' + colour + '"> <i class="fa ' + icon + ' fa-2x" ></i></font>'
//if (rstate === 0) {
//    if (debug == 1) {
//        node.warn(
// (rest of old code for that block)

The original error:
Function tried to send a message of type string
So - it would seem - I am somehow still missing something.

Adding the line just after where msg1 is defined:
{"payload":"<font color = \"line\"> <i class=\"fa fa-bullseye fa-2x\" ></i></font>"}
which - to me - looks ok.

Further update:

If I add the node.warn(msg1) just before the return [msg1,msg2,msg3, msg4] line.
(in this case to help identify it
node.warn("sending " + msg1)
I get/see this:
sending [object Object]

Now that's interesting.

I'm digging a hole for myself.

(Over)thinking it I think I see another way to reduce the code size.

New code.

    bit = sender_i -1
    if (router == "offline") {
    //
    rstate = clearBit(rstate, bit)
    context.set("rstate", rstate)
    }
    if (router == "online") {
        //
        rstate = setBit(rstate, bit)
        context.set("rstate", rstate)
    }
    //      Publib IP
    if (pip == "offline") {
        //
        pstate = clearBit(pstate, bit)
        context.set("pstate", pstate)
    }
    if (pip == "online") {
        //
        pstate = setBit(pstate, bit)
        context.set("pstate", pstate)
    }
    //      modem
    if (modem == "offline") {
        //
        mstate = clearBit(mstate, bit)
        context.set("mstate", mstate)
    }
    if (modem == "online") {
    //
        mstate = setBit(mstate, bit)
        context.set("mstate", mstate)
    }
    //      Internet IP
    if (internet == "offline") {
        //
        istate = clearBit(istate, bit)
        context.set("istate", istate)
    }
    if (internet == "online") {
        //
        istate = setBit(istate, bit)
        context.set("istate", istate)
    }

Working from old code:
sender_i is numbered 1,2,3
The bits used in the code are 0,1,2
Only to have it quick changeable if it doesn't work, I've put this in a if() nest
So I get sender_i and subtract 1 from it and I then get 0,1,2 rather than 1,2,3

So that removes the whole switch(sender_i) part.
Not much, I know, but.....
For the sake of moving forward. :wink:

The problems I mentioned in the earlier post are now seeming to have gone away.
For ever? Not sure. But for now they have.
If you have any ideas on them: I am still interested.

If this new code works, I will change the sender_i to be 0,1,2 and remove the bit = sender_i -1 and just put sender_i in those lines.

P.S.
Having said the problems/error went away.
As soon as I posted and went back to testing: It's back.
Function tried to send a message of type string

I think it was the <I that was mentioned.
I'd forgotten to fix that.
Sorry.

Ok, after...... 5 hours of sitting here trying things.

New code.
A lot of REDUNDANT stuff in it because I want to be able to go back to a working version if it fails.
That is done with test and test1
I hope I have cearly marked the blocks to show the changes.

code:

/////////////////////////////////
//
//  Routines.
//
//Set Bit
function setBit(number, bitPosition) {
    return number | (1 << bitPosition);
}
//
//Clear Bit
function clearBit(number, bitPosition) {
    const mask = ~(1 << bitPosition);
    return number & mask;
}
//
//  getColour
function getColour(number) {
    let colour; // Declare the variable

    if (number > 4) {
        colour = "lime";
    } else if (number > 1) {
        colour = "green";
    } else if (number === 1) {
        colour = "springgreen";
    } else if (number === 0) {
        colour = "red";
    }

    return colour; // Return the colour
}
//
/////////////////////////////////

if (msg.payload == "WIPE") {
    //
    context.set("rstate", 0)
    context.set("pstate", 0)
    context.set("mstate", 0)
    context.set("istate", 0)
    node.status({ text: "RESET" })
    return;
}

if (msg.payload == "DEBUG") {
    context.set("debug", msg.onoff);
    if (msg.onoff == 0) {
        node.status({});
    } else {
        node.status({ fill: "blue", text: "DEBUG ON" });
    }
    return;
}

let msg1 = {}   //  router
let msg2 = {}   //  pip
let msg3 = {}   //  Telstra modem
let msg4 = {}   //  internet

let debug = context.get("debug")

let sender = msg.payload.Who
let sender_i

let router = msg.payload.router
let pip = msg.payload.pip
let modem = msg.payload.modem
let internet = msg.payload.internet

if (pip == "unknown")
{
    context.set("pstate","unknown")
}

if (debug == 1) {
    //
    node.warn("Who " + sender + " router " + router + " pip " + pip + " modem " + modem + " internet " + internet)
}

//      Edit in each machine so weights are correct
switch (sender) {
    case "BedPi":
        sender_i = 1
        break
    case "TelePi":
        sender_i = 2
        break
    case "TimePi":
        sender_i = 3
        break
}


let bit
let rstate = context.get("rstate") || 0
let pstate = context.get("pstate") || 0
let mstate = context.get("mstate") || 0
let istate = context.get("istate") || 0


if (debug == 1)
{
    node.warn("Sender " + sender)
    node.warn("sender_i " + sender_i)
    node.warn("Router " + router)
    node.warn("PIP " + pip)
    node.warn("modem " + modem)
    node.warn("Internet " + internet)

    node.warn("rstate " + rstate)
    node.warn("pstate " + pstate)
    node.warn("mstate " + mstate)
    node.warn("istate " + istate)
}

// 1 = old
// 0 = new
//////      This works.  Use new code.  (test1 = 0)
let test1 = 0

if (test1 == 0)
{
    bit = sender_i -1
    if (debug == 1)
    {
        //
        node.warn("Bit = " + bit + " " + rstate + " " + pstate + " " + mstate + " " + istate)
    }
    if (router == "offline") {
    //
    rstate = clearBit(rstate, bit)
    context.set("rstate", rstate)
    }
    if (router == "online") {
        //
        rstate = setBit(rstate, bit)
        context.set("rstate", rstate)
    }
    //      Publib IP
    if (pip == "offline") {
        //
        pstate = clearBit(pstate, bit)
        context.set("pstate", pstate)
    }
    if (pip == "online") {
        //
        pstate = setBit(pstate, bit)
        context.set("pstate", pstate)
    }
    //      modem
    if (modem == "offline") {
        //
        mstate = clearBit(mstate, bit)
        context.set("mstate", mstate)
    }
    if (modem == "online") {
    //
        mstate = setBit(mstate, bit)
        context.set("mstate", mstate)
    }
    //      Internet IP
    if (internet == "offline") {
        //
        istate = clearBit(istate, bit)
        context.set("istate", istate)
    }
    if (internet == "online") {
        //
        istate = setBit(istate, bit)
        context.set("istate", istate)
    }
    node.status({ text: rstate + " " + pstate + " " + mstate + " " + istate })
}
/////////////////////////
if (test1 == 1)
{
switch (sender_i) {
    case 1:
        bit = 0
        if (debug == 1) {
            node.warn("Bit " + bit)
        }
        //      Router
        if (router == "offline") {
            //
            rstate = clearBit(rstate, bit)
            context.set("rstate", rstate)
        }
        if (router == "online") {
            //
            rstate = setBit(rstate, bit)
            context.set("rstate", rstate)
        }
        //      Publib IP
        if (pip == "offline") {
            //
            pstate = clearBit(pstate, bit)
            context.set("pstate", pstate)
        }
        if (pip == "online") {
            //
            pstate = setBit(pstate, bit)
            context.set("pstate", pstate)
        }
        //      modem
        if (modem == "offline") {
            //
            mstate = clearBit(mstate, bit)
            context.set("mstate", mstate)
        }
        if (modem == "online") {
            //
            mstate = setBit(mstate, bit)
            context.set("mstate", mstate)
        }
        //      Internet IP
        if (internet == "offline") {
            //
            istate = clearBit(istate, bit)
            context.set("istate", istate)
        }
        if (internet == "online") {
            //
            istate = setBit(istate, bit)
            context.set("istate", istate)
        }
        node.status({ text: rstate + " " + pstate + " " + mstate + " " + istate })
        break
    case 2:
        bit = 1
        if (debug == 1) {
            node.warn("Bit " + bit)
        }
        //      Router
        if (router == "offline") {
            //
            rstate = clearBit(rstate, bit)
            context.set("rstate", rstate)
        }
        if (router == "online") {
            //
            rstate = setBit(rstate, bit)
            context.set("rstate", rstate)
        }
        //      Publib IP
        if (pip == "offline") {
            //
            pstate = clearBit(pstate, bit)
            context.set("pstate", pstate)
        }
        if (pip == "online") {
            //
            pstate = setBit(pstate, bit)
            context.set("pstate", pstate)
        }
        //      modem
        if (modem == "offline") {
            //
            mstate = clearBit(mstate, bit)
            context.set("mstate", mstate)
        }
        if (modem == "online") {
            //
            mstate = setBit(mstate, bit)
            context.set("mstate", mstate)
        }
        //      Internet IP
        if (internet == "offline") {
            //
            istate = clearBit(istate, bit)
            context.set("istate", istate)
        }
        if (internet == "online") {
            //
            istate = setBit(istate, bit)
            context.set("istate", istate)
        }
        node.status({ text: rstate + " " + pstate + " " + mstate + " " + istate })
        break
    case 3:
        bit = 2
        if (debug == 1) {
            node.warn("Bit " + bit)
        }
        //      Router
        if (router == "offline") {
            //
            rstate = clearBit(rstate, bit)
            context.set("rstate", rstate)
        }
        if (router == "online") {
            //
            rstate = setBit(rstate, bit)
            context.set("rstate", rstate)
        }
        //      Publib IP
        if (pip == "offline") {
            //
            pstate = clearBit(pstate, bit)
            context.set("pstate", pstate)
        }
        if (pip == "online") {
            //
            pstate = setBit(pstate, bit)
            context.set("pstate", pstate)
        }
        //      modem
        if (modem == "offline") {
            //
            mstate = clearBit(mstate, bit)
            context.set("mstate", mstate)
        }
        if (modem == "online") {
            //
            mstate = setBit(mstate, bit)
            context.set("mstate", mstate)
        }
        //      Internet IP
        if (internet == "offline") {
            //
            istate = clearBit(istate, bit)
            context.set("istate", istate)
        }
        if (internet == "online") {
            //
            istate = setBit(istate, bit)
            context.set("istate", istate)
        }
        node.status({ text: rstate + " " + pstate + " " + mstate + " " + istate })
        break
    }
}
////    END OF TEST block
if (debug == 1) {
    node.warn("half way through " + rstate + " " + pstate + " " + mstate + " " + istate)
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

let colour
let icon


// test 1 = new code
// test 0 = old code
//
//  This seems to be working.  Use NEW CODE - test == 1
//
let test = 1

//      ==============      ROUTER
if (test == 1)
{
    colour = getColour(rstate)
    icon = "fa-bullseye"
    msg1.payload = '<font color = "' + colour + '"> <i class="fa ' + icon + ' fa-2x" ></i></font>'
    if (debug == 1)
    {
        node.warn("A " + msg1.payload)
    }
}
else 
if (test == 0)
{
    //
    if (debug == 1)
    {
        node.warn("rstate value " + rstate)
    }
    if (rstate === 0) {
        if (debug == 1) {
            node.warn("rstate == 0")
        }
        mstate = "UNKNOWN";
        msg1 = { payload: '<font color = "red"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "black" };
        msg2 = { payload: '<font color = "red"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "black" };
        msg3 = { payload: '<font color = "red"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "black" };
        msg4 = { payload: '<font color = "red"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "black" };
    } else

        if (rstate > 4) {
            if (debug == 1) {
                node.warn("rstate > 4")
            }
            msg1 = { payload: '<font color = "lime"> <i class="fa fa-bullseye fa-2x"></i></font>', colour: "lime" };
        } else

            if (rstate > 1) {
                if (debug == 1) {
                    node.warn("rstate > 2")
                }
                msg1 = { payload: '<font color = "green"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "green" };
            } else

                if (rstate == 1) {
                    if (debug == 1) {
                        node.warn("rstate == 1")
                    }
                    msg1 = { payload: '<font color = "springgreen"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "springgreen" };
                }

//    node.warn("A " + msg1.payload)

}
if (debug == 1) {
    node.warn("end of rstate ")
    node.warn(msg1.payload)
    node.warn("rstate payload above")
}


//      ==============      Pulic IP
if (pstate === 0) {
    msg2 = { payload: '<font color = "red"> <i class="fa fa fa-bullseye fa-2x" ></i></font>', colour: "red" };
} else

    if (pstate > 4) {
        msg2 = { payload: '<font color = "lime"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "lime" };
    } else

        if (pstate > 1) {
            msg2 = { payload: '<font color = "green"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "green" };
        } else

            if (pstate == 1) {
                msg2 = { payload: '<font color = "springgreen"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "springgreen" };
            } else

                if (pstate == "unknown") {
                    msg2 = { payload: '<font color = "black"> <i class="fa fa-question-circle fa-2x" ></i></font>', colour: "black" };
                }

if (debug == 1) {
    node.warn("end of pstate ")
    node.warn(msg2.payload)
}



//      ==============      Telstra modem
if (mstate === 0) {
    msg3 = { payload: '<font color = "red"> <i class="fa fa fa-bullseye fa-2x" ></i></font>', colour: "red" };
} else

    if (mstate > 4) {
        msg3 = { payload: '<font color = "lime"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "lime" };
    } else

        if (mstate > 1) {
            msg3 = { payload: '<font color = "green"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "green" };
        } else

            if (mstate == 1) {
                msg3 = { payload: '<font color = "springgreen"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "springgreen" };
            } else

                if (mstate == "UNKNOWN") {
                    msg3 = { payload: '<font color = "black"> <i class="fa fa-question-circle fa-2x" ></i></font>', colour: "black" };
                }

if (debug == 1) {
    node.warn("end of mstate ")
    node.warn(msg3.payload)
}


//node.warn("C " + msg1.payload)


//      ==============      Internet IP
if (debug == 1)
{
    //
    node.warn("*******")
}

let icon1 = "fa-bullseye"
let icon2 = "fa-wifi"
if (pstate == 0)
{
    icon = icon2
} else
{
    icon = icon1
}

//
//  new code for testing internet icon.
//
if (test == 1) {
    colour = getColour(istate)
    //icon = "fa-bullseye"
    //msg1.payload = '<font color = "' + colour + '"> <i class="fa ' + icon + ' fa-2x" ></i></font>'
    msg4.payload = '<font color = "' + colour + '"> <i class="fa ' + icon + ' fa-2x" ></i></font>'
    msg4.colour = colour
    if (debug == 1) {
        node.warn("A " + msg4.payload)
    }
}
else
if (test == 0)
{
    if (istate === 0) {
        msg4 = { payload: '<font color = "red"> <i class="fa fa fa-bullseye fa-2x" ></i></font>', colour: "red" };
    } else

        if (istate > 4) {
            //
            //  '<font color = "' + colour + '"> <i class="fa ' + icon + ' fa-2x" ></i></font>'
            //
            //msg4 = '{ payload:' + icon3 + ', colour: "lime" }';
            msg4.payload = '<font color = "lime"> <i class="fa ' + icon + ' fa-2x" ></i></font>'
        } else

            if (istate > 1) {
                msg4 = { payload: '<font color = "green"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "green" };
            } else

                if (istate == 1) {
                    msg4 = { payload: '<font color = "springgreen"> <i class="fa fa-bullseye fa-2x" ></i></font>', colour: "springgreen" };
                } else

                    if (istate == "UNKNOWN") {
                        msg4 = { payload: '<font color = "black"> <i class="fa fa-question-circle fa-2x" ></i></font>', colour: "black" };
                    }
}
if (debug == 1) {
node.warn("end of internet ")
node.warn("msg4 " + msg4.payload)
node.warn("msg3 " + msg3.payload)
node.warn("msg2 " + msg2.payload)
node.warn("msg1 " + msg1.payload)
}

return [msg1, msg2, msg3, msg4]

Is/are the improvements of benefit?

Ok, that's a difficult question.
I'm just wanting to know if I have seemed to have learnt anything by doing it the second way.