Hi Alexei -
With regard to:
Whilst I may not be able to help with specifics for your device, I’m just wondering what your use-case is for this field. The way I understand it this is a field used to set alarm thresholds and conditions (or reading the currently configured thresholds), but does not present the alarm flags themselves.
If this (threshold conditions) is something you want to set & forget, probably using the Tuya app is (hopefully) the easiest way to set them. And if not available in the App, you may be able to set via the Tuya IoT debug page?
But if you do have a use case where you want to update them from OpenHAB, then you virtually have to turn my script completely around and would (as a guess) be “Items>Hex>Base64”. And that also comes with another warning - Does your use case require frequent updates? I have had a device previously which through a firmware fault, was continually updating values in Non-Volatile Storage, which the vendor needed to replace the whole device due to wearing this out pretty quickly (Like think somewhere between 5000 and 10000 rated write cycles). No idea what is inside your device, but I also have other devices which warn against frequent updates.
If however you are happy to set alarm thresholds from the Tuya App, and you are just trying to get the alarm status, that would be in something like the Tuya ‘fault’ bitmap field. If that is the case, then the following script I wrote for another device type, to update OpenHAB items based on bitmap values may be of help to you?:
zflags = items.getItem("ZelioFlags_Output").state;
setState("ZelioHWCElement",0,zflags);
setState("ZelioUnderfloorCirc",1,zflags);
setState("ZelioRingMainCirc",2,zflags);
setState("ZelioSolarCirc",3,zflags);
setState("ZelioWBRumpusCirc",4,zflags);
setState("ZelioWBLivingCirc",5,zflags);
setState("ZelioAlarmArmed",6,zflags);
setState("ZelioGarageNorthDoorClosed",8,zflags);
setState("ZelioGarageSouthDoorClosed",9,zflags);
setState("ZelioWoodshedDoorClosed",10,zflags);
function setState(item,bitpos,zflags) {
/* Function to update status of items, based on a bit status
Parameters as follows:
- item - The name of the OpenHAB item to update with ON or OFF (Expects Item to be a Switch type)
- bitpos - The bit position in the source data to read
- zflags - The source data from which to read the Status
*/
switch(getBit(zflags,bitpos)){
case "ON" :
items[item].sendCommandIfDifferent("ON");
console.debug("Changing state to ON for:",items.getItem(item).name);
break;
case "OFF" :
items[item].sendCommandIfDifferent("OFF");
console.debug("Changing state to OFF for:",items.getItem(item).name);
break;
default:
console.log("Unknown state for:",items[item].name);
}
}
function getBit(number, bitPosition) {
// Function to read individual bits and return status
return (number & (1 << bitPosition)) === 0 ? "OFF" : "ON";
}
Noting the following:
- It is a quick and dirty script I wrote when I was starting out with JS scripting in OpenHAB, so everything is hardcoded in there (Would do it differently now)
- You set this rule up to run every time the Tuya ‘fault’ item changes, and also on start-level 100 (I needed that for my use case anyway)
- Just update the ‘setState’ lines with the bit position, and the associated OpenHAB switch item you want to update (In your case it might be a overcurrent alarm switch, under voltage switch, over voltage switch), and add more lines as needed (Are there 16 flags for your device?)
- And a final disclaimer - I have NOT used the Tuya fault bitmap field for my EV wallbox. All the bits represent fairly serious issues (not threshold limits like your device does), so I really have not bothered setting this up, as there is no way of testing this… safely
![:slight_smile: :slight_smile:](https://community.openhab.org/images/emoji/twitter/slight_smile.png?v=12)
Good luck, and hope this helps.