RM sends stored variable with color parameter as HTML tag(s)

Any idea how to strip/store the rule without the HTML code (without modifying the driver)?

Variable is grabbed from a driver that displays the sting with various colors and stored as a string (no html tags visible).

The notification goes out like this:

What driver is this? While you could probably do some naive operations in RM to modify this text (substring involving > and <, maybe?), it would be a lot easier to tackle this at the driver level--and if you share what that driver actually is, maybe someone already knows a way.

Driver is [RELEASE] IKEA Zigbee drivers

The air quality driver to be exact.

I extract the custom atribute and store it in a variable that I pass in the notification.

The text is stored like this:

Variable is getting the custom atribute and stores it like this:

(notice the color).

The notification that included the %Variable% sends it as the screenshot in the first post.

@gopher.ny , @bobbyD

I believe this has something to do with how the variable is set (HTML tags migrate from the original string), where the value is not stored as a “plain” string value.

Is this the desired behavior?

Variable is set with the following rule:

No, this has everything to do with how the driver is setting the value. The attribute value includes HTML. The device detail page renders this. A hub variable is going to just give you the underlying string value, which includes the visible HTML tags. The hub variable is doing what it is supposed to do.

One solution is to ask the driver author for an option to disable HTML and set the values as plain text.

Another solution is to use the AQI itself and create your own string from that, given that this value is simply a human-friendly convenient display of that same information.

A third option is the one I mentioned above, using some string operations in Rule Machine to cut the variable value down to just what you need. Since this HTML is fairly simple (i.e., the complexities of a full parser are unlikely to really matter), breaking the string apart using tokenizers on < and then > (or the other way around) using the appropriate indicies should also help you get the text you're really after.

1 Like

@dandanache

Do you accept a PR to the code with the following 2 lines added ?

attribute 'airQualityPlain', 'enum', ['good', 'moderate', 'unhealthy for sensitive groups', 'unhealthy', 'hazardous']

As line 35

And

utils_sendEvent name:'airQualityPlain', value:"${aqi[1]}", descriptionText:"Calculated Air Quality = ${aqi[1]}", type:type

As line 320

(Or you can add it …)

I did the changes on my side but obviously they wont survive a driver update😊

1 Like

I think the best way forward is to remove the HTML code from the existing attribute. Since it was a custom attribute, I took the liberty to be creative; looks like it was a bad call since the HTML color brings more problems than benefits. I'll include the changes in the next release. Thank you for the feedback!

1 Like

I do like the color aspect :blush: which might help with a dashboard integration.

I kept it on my side, just for that reason, and added the simple ones for other variable(s) use.