- Platform information:
- Hardware: Intel
- OS: Windows Server 2022
- Java Runtime Environment: zulu17.46.19-ca-jdk17.0.9-win_x64
- openHAB version: 4.0.3
Hi, guru! I really need your help!
I’m trying to connect a Zanussi I-09/HB/A23/N8 air conditioner to OpenHAB.
It is controlled via MQTT.
Some functions are controlled through a topic in the form of a regular string 00000000, where the value can be 0 or 1. Binary flags, but in the form of a string.
For example,
- if I want to set ECO mode, I must send a line in the form 01000000
- if I want to set UV mode, I must send a line in the form 00000001
It’s simple, but these are flags and some bits can already be set or cleared.
When sending a command, I must get the current state, set/uncheck the desired flag, and send the command.
For example:
- Current state 00000001 - UV mode enabled
- I set the mode to Eco and leave the UV mode running: 01000001, and send the command.
- Current state 01000001 - UV mode enabled
But I don’t understand how I can implement this in OpenHab.
To control and display states, I made two ordinary switches and associated them with thing channels.
Third item for diagnostics (ac_ctrl_data)
Things channels
- id: ac_ctrl_data
channelTypeUID: mqtt:string
label: "AC control data: for diag and debug"
description: null
configuration:
postCommand: true
stateTopic: ac/dev01/state/data
commandTopic: ac/dev01/control/data
- id: control_mode_eco
channelTypeUID: mqtt:switch
label: "ECO mode: 01000000"
configuration:
postCommand: true
stateTopic: ac/dev01/state/data
transformationPattern: JS:hommyn\zacs-data-state.js?idx=1
commandTopic: ac/dev01/control/data
transformationPatternOut: JS:hommyn\zacs-data-command.js&idx=1
- id: control_mode_uvc
channelTypeUID: mqtt:switch
label: "UV mode: 00000001"
configuration:
postCommand: true
stateTopic: ac/dev01/state/data
transformationPattern: JS:hommyn\zacs-data-state.js?idx=1
commandTopic: ac/dev01/control/data
transformationPatternOut: JS:hommyn\zacs-data-command.js&idx=1
Scripts:
// zacs-data-state.js: Check flag and return switch state
(function(data /* String XXXXXXXX */, index /* order from left */) {
return (8 == data.length && '1' == data.charAt(index) ? 'ON' : 'OFF');
})(input, index)
// zacs-data-command.js: Set flag and publish command (OnOffType to String)
(function(command /* OH4 Switch: OnOffType */, index /* order from left */) {
const setAt = (where, idx, what) => { return (where.slice(0, idx) + what + where.slice(idx + what.length)); }
// HOW I CAN GET STATE OF CONTROL DATA: items.ac_ctrl_data channel.state???!!!!
let _state = '00000000';
// Return '01000000' if Command=ON and index=1
return setAt(_state, parseInt(index), ('ON' == command ? '1': '0'));
})(input, index)
As far as I understand, I cannot access items or things in transformations. Then how can I take the current state and mark the flag when sending a command (zacs-data-state.js)?
I hope I explained it clearly)) Perhaps there is some other way!!!
Help me!