MAP string / number item on string channel

Hello everyone,

I have a Zigbee thermostat which supplies the system mode as a string via a channel (on, heat, auto)

However, I need a number item in a rule. Therefore I have added another item (number) to the channel.

To do this, I created a MAP transformation.

off=0
heat=1
auto=2

In the one direction, i.e. change the system mode on the Zigbee device, it works and my number item is 0, 1 or 2. However, if I change the number item, nothing appears on the Zigbee device.

Where is my mistake here?

Have you tried just using the string in the rule?
You can alsp map in the rule

I agree with @garyfree , this definitely seems like an XY Problem. Why do you need a number in the rule? Why can’t you do the mapping in the rule?

Not enough information to answer. How is the profile configured? Are there any other transformations involved? How are you “changing” the Number Item?

I have now solved this as follows.

I have removed the mapping in the channel configuration. My item is now a string item.

I have a rule for heating control in which other thermostats are also controlled.

The item name (itemSystemMode) of the thermostat system mode is derived from the room name + ‘Heizkorperthermostat_Thermostatmode’.

var itemSystemMode = rootRoom + 'Heizkorperthermostat_Thermostatmode';

I have now introduced a distinction in the rule as to which item type it is and then adapt the send command accordingly (see below).

if (activeProfile == 'Aus') {
    // OFF = 0, HEAT = 1, HEAT_ECON = 2, FULL_POWER = 3
    if (items.getItem(itemSystemMode).type == 'Number') {
      if (items.getItem(itemSystemMode).state == 1 || items.getItem(itemSystemMode).state == 2 || items.getItem(itemSystemMode).state == 3) {
	    items.getItem(itemSystemMode).sendCommand(0);
      }
    } else {
      if (items.getItem(itemSystemMode).state == 'heat' || items.getItem(itemSystemMode).state == 'auto') {
	    items.getItem(itemSystemMode).sendCommand('off');
      }
    }

Two alternative implementations of your code:

const item = items[itemSystemMode]
switch (item.state) {
  case 'heat':
  case 'auto':
    item.sendCommand('off')
    break
  case 1:
  case 2:
  case 3:
    item.sendCommand(0)
    break
}
const mapping = {
  heat: 'off',
  auto: 'off',
  1: 0,
  2: 0,
  3: 0
}

const item = items[itemSystemMode]
const command = mapping[item.state]
if (command) {
  item.sendCommand(command)
}

Thanks for the tips, I have now installed it as follows. Otherwise it didn’t work. The quotation marks in the numbers were necessary, for whatever reason

var mapThermostatHeat = {
	off:  'heat',
	auto: 'heat',
	0:    '1',
	2:    '0',
	3:    '0'
	};

var mapThermostatOff = {
	heat: 'off',
	auto: 'off',
	1: 	  '0',
	2:    '0',
	3:    '0'};

var item = items[itemSystemMode];
if (activeProfile == 'Aus') {
	const commandOff = mapThermostatOff[item.state];
    if (commandOff) {
      item.sendCommand(commandOff)
    }
    if (log == 'ON') console.info('No active profile, check ' + rootRoom + '_Heating_WindowSuspension');
  } else if (activeProfile != 'Aus') {
    const commandHeat = mapThermostatHeat[item.state];
    if (commandHeat) {
      item.sendCommand(commandHeat)
    }

var mapThermostatHeat = {
  off:  'heat',
  auto: 'heat',
  0:    '1',
  2:    '0',
  3:    '0'
}

var mapThermostatOff = {
  heat: 'off',
  auto: 'off',
  1: 	  '0',
  2:    '0',
  3:    '0'
}

var item = items[itemSystemMode]
const map = activeProfile === 'Aus' ? mapThermostatOff : mapThermostatHeat
const command = map[item.state]
if (command) {
  item.sendCommand(command)
}