Closed Schnabulation closed 1 year ago
This is a bit tricky because the control sensor value can basically be anything: a number, a text-string, a boolean or whatever you decide. So, for the moment I'm using "negative" checking. The "default" value is always set to "sensor control disabled", so if it's NOT that display the module... It will be a real pain to check everything "else" in another way. :)
Thanks for your feedback. I have checked your code and can understand what you mean.
May I suggest the following approach? (Attention: this is just pseudo code and needs clean up)
defaults: {
controlsensorcompare: 'equal' // The comparison algorithm that the control sensor will have.
},
if (this.config.controlsensor !== "sensor control disabled") {
var stateval = this.getState(data, this.config.controlsensor);
var compareval = this.getState(data, this.config.controlsensorcompare);
switch (compareval) {
case "equal":
if ((stateval !== this.config.controlsensorvalue && this.config.controlsensorvalue !== "sensor control disabled")) {
// this.hide() does not work well with MMM-Pages, so use wrapper.style.display instead
if (wrapper.style.display != "none") {
this.visibleStyle = wrapper.style.display;
wrapper.style.display = "none";
}
} else {
if (wrapper.style.display == "none") {
wrapper.style.display = this.visibleStyle;
}
}
case "above":
if ((stateval < this.config.controlsensorvalue)) {
// this.hide() does not work well with MMM-Pages, so use wrapper.style.display instead
if (wrapper.style.display != "none") {
this.visibleStyle = wrapper.style.display;
wrapper.style.display = "none";
}
} else {
if (wrapper.style.display == "none") {
wrapper.style.display = this.visibleStyle;
}
}
case "below":
if ((stateval > this.config.controlsensorvalue)) {
// this.hide() does not work well with MMM-Pages, so use wrapper.style.display instead
if (wrapper.style.display != "none") {
this.visibleStyle = wrapper.style.display;
wrapper.style.display = "none";
}
} else {
if (wrapper.style.display == "none") {
wrapper.style.display = this.visibleStyle;
}
}
case "notequal":
if ((stateval == this.config.controlsensorvalue)) {
// this.hide() does not work well with MMM-Pages, so use wrapper.style.display instead
if (wrapper.style.display != "none") {
this.visibleStyle = wrapper.style.display;
wrapper.style.display = "none";
}
} else {
if (wrapper.style.display == "none") {
wrapper.style.display = this.visibleStyle;
}
}
}
// If the control sensor value is anything not the default or not the defined value, hide the module.
}
Hmm... That may work... Not sure of you can compare a string with "above" ( > greater then) or "below" ( < Less then) in this way? If you want to try it, just fork and test, if it works, send a PR. :) But I can see that it would be a good idea, maybe we could do it / sensor bases instead... I'll have to think about it. :)
Ok, I have added a "highDisplayThreshold" and "lowDisplayThreshold". These can be used to only display sensors in the "specified" range... Let me know if this works... :)
Amazing! Thank you very much!
Hi all
Just a quick feature request: It would be neat if one could use the
controlsensorvalue
with a decimal value and a logarithmic comparison.Ex.
Thank you and best regards