ottopaulsen / MMM-MQTT

MQTT Client module for MagicMirror2
MIT License
57 stars 29 forks source link

Change the colors of non-numeric values #37

Closed majdzik84 closed 3 years ago

majdzik84 commented 3 years ago

Hi. Thank you for your module. Can I easily colorize non-numeric values? I really care about determining the air quality along with the color. (if/endif?)

    colors: [             // Value dependent colors
                        { if: 'bardzo dobre', value: "blue", label: "blue", suffix: "blue" },
                        {endif: 'dobre', value: "#00ccff", label: "#00ccff", suffix: "#00ccff" },
                        { endif: 'umiarkowane', value: "yellow"},
                        { endif: 'złe', label: "green", suffix: "green" },
                        { else: 'bardzo złe', label: "red" }, // The last one is used for higher values too
ottopaulsen commented 3 years ago

Hi

Take a look at the Conversions section in the README. There you can see how I display icons in different colors based on non-numeric values. If you want text, i believe you can use something like this:

<span style='color:green'>Your text</span>

Or maybe text-color or something else. Please give it a try, and let me know how it turns out.

Otto

vemeT5ak commented 3 years ago

I gave this a brief test. No luck and broke the config file. { topic: 'waterheater/leak', label: 'Waterheater', sortOrder: 30, maxAgeSeconds: 60 conversions: [ { from: "All dry", to: <span style='color:green'>"All dry"</span> }, { from: "LEAK!!!", to: <span style='color:red'>"LEAK!!!"</span> } ] },

ottopaulsen commented 3 years ago

Be careful with your quotes. I believe the <span style='color:green'>"All dry"</span> should be changed to "<span style='color:green'>All dry</span>", and the <span style='color:red'>"LEAK!!!"</span> should be "<span style='color:red'>LEAK!!!</span>".

The config file is a json file, and must be legal json. You may get help from a good editor.

vemeT5ak commented 3 years ago

Hmm, the hunt continues. seems anytime I include conversions, even from the example, the config file breaks. Be very quiet I'm hunting Bugs (Bunny)

vemeT5ak commented 3 years ago

Hmm, the hunt continues. seems anytime I include conversions, even from the example, the config file breaks. Be very quiet I'm hunting Bugs (Bunny)

Updated information. The conversion text works!!. However, if one adds the sort order or maxAgeSeconds, the config breaks.

vemeT5ak commented 3 years ago

Hmm, the hunt continues. seems anytime I include conversions, even from the example, the config file breaks. Be very quiet I'm hunting Bugs (Bunny)

Updated information. The conversion text works!!. However, if one adds the sort order or maxAgeSeconds, the config breaks.

IT WORKS!!! Seems the placement of the sortOrder and MaxAgeSeconds is important. The both of them should be placed before the topic. { sortOrder: 30, maxAgeSeconds: 60, topic: 'waterheater/leak', label: 'Waterheater', conversions: [ { from: "All dry", to: "<span style='color:green'>All dry</span>" }, { from: "LEAK!!!", to: "<span style='color:red'>LEAK!!!</span>" } ] },

ottopaulsen commented 3 years ago

Looks like you got this right. The order of the config variables has nothing to say, but you may have had another error. Closing this.