Достаточно экранировать.
mosquitto_pub -t "/devices/colorButton/controls/Dimmer 1/on" -m "#8C1A1A"
Использовать правильные типы значений. Ну и соответственно не пытаться писать в value text
Попытка взять “первый символ” из числа, не преобразовывая его в строку - заведомо неудачна.
//12_14_test3.js
defineVirtualDevice("colorButton",
{
title: "Color Buttons",
cells: {
"Dimmer 1": {
type: "text",
readonly: false,
//forceDefault: true,
value: "",
},
}
});
defineRule("color_convert", {
whenChanged: "colorButton/Dimmer 1",
then: function (newValue, devName, cellName){
log.info("I’m here!", newValue, newValue.substring(0,1))
if(newValue.substring(0,1) == "#") {
newValue = newValue.substring(1);
}
var rgbColor = {};
rgbColor.r = parseInt(newValue.substring(0,2),16);
rgbColor.g = parseInt(newValue.substring(2,4),16);
rgbColor.b = parseInt(newValue.substring(4),16);
color = rgbColor;
log(rgbColor);
}
});