Problem adding a switch to a dimmer

Using openhab 4.1.2 in docker, I added a dimmer using mqtt-homeassistant. I thought it wasn’t working, because I was missing a state to create a switch, but it appear it is the expected behavior. Now I try to create a switch from dimmer channel, but it fails. I think it is a unit problem.

You can treat a Dimmer Item like a Switch. You can send such an Item ON/OFF commands for example an in a rule you can getStateAs(OnOffType) to get the state of the Dimmer as ON or OFF.

You cannot link a Dimmer Channel to a Switch Item though. You still much link the Channel to a Dimmer Item. But you can treat that Dimmer Item as if it were a Switch Item.

I do this this all the time.

It works just fine for me and has for many years. Way back in the OH history lost in the mists of time, I think it was even the recommended method (though I barely remember what I had for dinner last night so I could be mis-remembering that as well). I’ve got this setup on all of my dimmer lights (at least 10, maybe more). It doesn’t matter much for rules for the reasons you point out, but it does make many of my widgets far simpler. Dimmer items, can of course be shoehorned into toggles for the widgets, but when aggregating various items, especially if you use the semantic metadata to do it separate items is much cleaner. For example I can have simple switches on one tab for all lights just getting Switch points and then sliders for any dimmer light on another tab just getting Setpoint points.

It is true that with the new UoM, you will get a state displayed as OFF % but that is easily fixable. Just add the pattern %s to the state description metadata.

However, the units should not impact whether the switch functions or not.

You might want to look into the configuration of the channel itself. I don’t know anything about Zigbee2mqtt, but I do know that some z-wave dimmers when going through mqtt such as with zwave-js-ui, the dimmer only goes from 0 - 99 so the automatic conversion of ON100 does not get received properly. In these cases there is a channel max value that you can configure so that the channel itself converts the 100 back down to 99 before sending along to the broker. For example, with the zwave it looks like this:

bridgeUID: mqtt:broker:9804d6aafe
location: Dining Room
channels:
  - id: Dimmer
    channelTypeUID: mqtt:dimmer
    label: Light Dimmer
    description: Dimming control
    configuration:
      commandTopic: zwjsui/80/38/0/targetValue/set
      step: 2
      min: 0
      stateTopic: zwjsui/80/38/0/currentValue
      max: 99

Otherwise, you might need a profile to do the 10099 conversion.

1 Like

I guess things change. Way back I was told you could use a Dimmer as a Switch but not link a Dimmer Channel to a Switch. I don’t have dimmers so haven’t kept up with those sorts of changes I guess. Maybe things changed when they made the type checking between the Item type and Channel Type looser to support Profiles which change the type of the Item (e.g. timestamp).

Since it’s a Dimmer Channel and not a Number:Dimensionless Channel, UoM shouldn’t come into play. But the binding likely does push a state description pattern along the lines of %s %% because the binding author assumes you’d only ever link it to a Dimmer Item. But this is display only and doesn’t involve the UoM subsystem. And in this case it’s probably largely a passthrough from the Homeassistant standard.

But the distinction is important because in a rule when you get the state, the state will be a PercentType, not a QuantityType<Dimensionless>.

If I’m not mistaken, this will result in a dimmer level of 99 as opposed to the previous state of the dimmer. Might just be a matter of personal preference, but most dimmers (all of mine anyway through zwave-js-ui) will respond to a restorePrevious topic.

For example:

zwave/Office/Office_Dimmer/switch_multilevel/endpoint_0/restorePrevious/set

I struggled to get this working within the channels, but ended up using rules on an unlinked switch (‘changed’ trigger):

if (items.getItem('OfficeLightsSwitch').state == 'ON') {
  if (items.getItem('OfficeLightsDimmer').state == '0') {
    things.getActions('mqtt', 'mqtt:broker:90b3ebebba').publishMQTT('zwave/Office/Office_Dimmer/switch_multilevel/endpoint_0/restorePrevious/set', 'true', 'FALSE' === 'TRUE');
  }
} else {
  items.getItem('OfficeLightsDimmer').sendCommand('0');
}

… and another rule to sync the switch with the manual dimmer.

You are absolutely, correct. I should have been more specific about that as a potential side-effect of linking the channel directly to the switch…

The few times my dimmers need to start at a non-full value, this is specified through rules and scenes, so I don’t need to worry about restoring the previous state, but it’s a valid concern.

If someone get around to building a dedicated zwave-js-ui binding then these concerns can all be handled internally, but I don’t know if that is on the horizon or not.

Ok, let’s go one step down to check if everything works:

binary_sensor/0x0c4314fffe0f8ab6/update_available
device_automation/0x0c4314fffe0f8ab6/action_off
device_automation/0x0c4314fffe0f8ab6/action_on
light/0x0c4314fffe0f8ab6/light
select/0x0c4314fffe0f8ab6/effect
select/0x0c4314fffe0f8ab6/power_on_behavior
sensor/0x0c4314fffe0f8ab6/linkquality
sensor/0x0c4314fffe0f8ab6/power_on_behavior
sensor/0x0c4314fffe0f8ab6/update_state
update/0x0c4314fffe0f8ab6/update

Don’t want to be a PEBCAT, but you tell us. Did the light dim to 100? Looks like it should…

Moving the slider does… nothing, that’s why I am asking if it should. I just have this dimmer so I don’t know what to expect.

If you don’t have MQTT Explorer, download that and see if the topics are updating when you move the slider. You can also publish to topics there to see if you can control the dimmer.

I enabled debug logs and…

2024-04-10 20:29:48.670 [WARN ] [qtt.generic.AbstractMQTTThingHandler] - Channel mqtt:homeassistant_zigbee2mqtt_5F0x0c4314fffe0f8ab6:mqtt-broker:mydimmer:brightness not supported!

when moving the slider

I also see

2024-04-10 20:59:51.321 [DEBUG] [ab.binding.mqtt.generic.ChannelState] - Transformation '{"action":"","brightness":254,"device":{"applicationVersion":33,"dateCode":"20190401","friendlyName":"cuinaLlumTaulell","hardwareVersion":2,"ieeeAddr":"0x0c4314fffe0f8ab6","manufacturerID":4476,"manufacturerName":"IKEA of Sweden","model":"ICPSHC24-30EU-IL-1","networkAddress":10014,"powerSource":"Mains (single phase)","softwareBuildID":"2.3.086","stackVersion":98,"type":"Router","zclVersion":3},"linkquality":87,"power_on_behavior":null,"state":"OFF","update":{"installed_version":587753009,"latest_version":587753009,"state":"idle"},"update_available":false}' returned null on 'JINJA', discarding message

@ccutrer is this expected?

I created a new docker with latest snapshot (4.2.0 Build #4031), enabled debug logs and:

2024-04-10 22:53:02.779 [WARN ] [qtt.generic.AbstractMQTTThingHandler] - Channel mqtt:homeassistant_zigbee2mqtt_5F0x0c4314fffe0f8ab6:257509d341:dimmmmer:brightness not supported!
2024-04-10 22:53:02.975 [WARN ] [qtt.generic.AbstractMQTTThingHandler] - Channel mqtt:homeassistant_zigbee2mqtt_5F0x0c4314fffe0f8ab6:257509d341:dimmmmer:brightness not supported!
2024-04-10 22:53:03.176 [WARN ] [qtt.generic.AbstractMQTTThingHandler] - Channel mqtt:homeassistant_zigbee2mqtt_5F0x0c4314fffe0f8ab6:257509d341:dimmmmer:brightness not supported!
2024-04-10 22:54:19.735 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '' from channel 'mqtt:homeassistant_zigbee2mqtt_5F0x0c4314fffe0f8ab6:257509d341:dimmmmer:0x0c4314fffe0f8ab6_5Fpower_5Fon_5Fbehavior_5Fzigbee2mqtt#select' not supported by type 'TextValue': Value  not within range
2024-04-10 22:54:19.743 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '' from channel 'mqtt:homeassistant_zigbee2mqtt_5F0x0c4314fffe0f8ab6:257509d341:dimmmmer:0x0c4314fffe0f8ab6_5Fpower_5Fon_5Fbehavior_5Fzigbee2mqtt#select' not supported by type 'TextValue': Value  not within range
2024-04-10 22:54:19.760 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '' from channel 'mqtt:homeassistant_zigbee2mqtt_5F0x0c4314fffe0f8ab6:257509d341:dimmmmer:0x0c4314fffe0f8ab6_5Fpower_5Fon_5Fbehavior_5Fzigbee2mqtt#select' not supported by type 'TextValue': Value  not within range
2024-04-10 22:54:45.091 [WARN ] [qtt.generic.AbstractMQTTThingHandler] - Channel mqtt:homeassistant_zigbee2mqtt_5F0x0c4314fffe0f8ab6:257509d341:dimmmmer:brightness not supported!

Do you have the Jinja transformation installed? It won’t automatically install it when you install the MQTT binding.

Already done

But I don’t select it, is it necessary?

My current language (ca) is missing in transformations, does it matter:
imatge

No, it’s not necessary to select it. That screenshot is of a Profile, which is an additional transformation that can optionally be applied to the link between a channel and an item. The Home Assistant binding directly and internally uses the Jinja transformation to process messages before they’re ever sent to the rest of openHAB - technically to the CommunicationManager, which is the intermediary between channels and items, but we’re getting into the weeds here. Suffice it to say I can now see you have Jinja installed, and that’s the only action you should need to take for what I was wondering might be the problem causing the log you posted.

Those are specific MAP transformations, which the Home Assistant binding doesn’t use at all. I’m not sure where those came from - I don’t have any language transformations in my instance, but maybe I deleted them long ago? My installation is nearly 6 years old at this point.

Next step, then: can you post the actual contents of the discovery topics from MQTT (The things under homeassistant/ that are relevant to this device)? You can use MQTT Explorer to find them. With that, I should be able to recreate your exact Thing.

ok here they go:
homeassistant/sensor/0x0c4314fffe0f8ab6/power_on_behavior/config

{"availability":[{"topic":"zigbee2mqtt/bridge/state","value_template":"{{ value_json.state }}"}],"device":{"identifiers":["zigbee2mqtt_0x0c4314fffe0f8ab6"],"manufacturer":"IKEA","model":"TRADFRI driver for wireless control (30 watt) (ICPSHC24-30EU-IL-1)","name":"cuinaLlumTaulell","sw_version":"2.3.086","via_device":"zigbee2mqtt_bridge_0x00124b0012c38fda"},"enabled_by_default":false,"entity_category":"diagnostic","icon":"mdi:power-settings","name":"Power-on behavior","object_id":"cuinallumtaulell_power_on_behavior","origin":{"name":"Zigbee2MQTT","sw":"1.36.0","url":"https://www.zigbee2mqtt.io"},"state_topic":"zigbee2mqtt/cuinaLlumTaulell","unique_id":"0x0c4314fffe0f8ab6_power_on_behavior_zigbee2mqtt","value_template":"{{ value_json.power_on_behavior }}"}

homeassistant/sensor/0x0c4314fffe0f8ab6/linkquality/config

{"availability":[{"topic":"zigbee2mqtt/bridge/state","value_template":"{{ value_json.state }}"}],"device":{"identifiers":["zigbee2mqtt_0x0c4314fffe0f8ab6"],"manufacturer":"IKEA","model":"TRADFRI driver for wireless control (30 watt) (ICPSHC24-30EU-IL-1)","name":"cuinaLlumTaulell","sw_version":"2.3.086","via_device":"zigbee2mqtt_bridge_0x00124b0012c38fda"},"enabled_by_default":false,"entity_category":"diagnostic","icon":"mdi:signal","name":"Linkquality","object_id":"cuinallumtaulell_linkquality","origin":{"name":"Zigbee2MQTT","sw":"1.36.0","url":"https://www.zigbee2mqtt.io"},"state_class":"measurement","state_topic":"zigbee2mqtt/cuinaLlumTaulell","unique_id":"0x0c4314fffe0f8ab6_linkquality_zigbee2mqtt","unit_of_measurement":"lqi","value_template":"{{ value_json.linkquality }}"}

homeassistant/sensor/0x0c4314fffe0f8ab6/update_state/config

{"availability":[{"topic":"zigbee2mqtt/bridge/state","value_template":"{{ value_json.state }}"}],"device":{"identifiers":["zigbee2mqtt_0x0c4314fffe0f8ab6"],"manufacturer":"IKEA","model":"TRADFRI driver for wireless control (30 watt) (ICPSHC24-30EU-IL-1)","name":"cuinaLlumTaulell","sw_version":"2.3.086","via_device":"zigbee2mqtt_bridge_0x00124b0012c38fda"},"enabled_by_default":false,"entity_category":"diagnostic","icon":"mdi:update","name":"Update state","object_id":"cuinallumtaulell_update_state","origin":{"name":"Zigbee2MQTT","sw":"1.36.0","url":"https://www.zigbee2mqtt.io"},"state_topic":"zigbee2mqtt/cuinaLlumTaulell","unique_id":"0x0c4314fffe0f8ab6_update_state_zigbee2mqtt","value_template":"{{ value_json['update']['state'] }}"}

homeassistant/binary_sensor/0x0c4314fffe0f8ab6/update_available/config

{"availability":[{"topic":"zigbee2mqtt/bridge/state","value_template":"{{ value_json.state }}"}],"device":{"identifiers":["zigbee2mqtt_0x0c4314fffe0f8ab6"],"manufacturer":"IKEA","model":"TRADFRI driver for wireless control (30 watt) (ICPSHC24-30EU-IL-1)","name":"cuinaLlumTaulell","sw_version":"2.3.086","via_device":"zigbee2mqtt_bridge_0x00124b0012c38fda"},"device_class":"update","enabled_by_default":false,"entity_category":"diagnostic","name":null,"object_id":"cuinallumtaulell_update_available","origin":{"name":"Zigbee2MQTT","sw":"1.36.0","url":"https://www.zigbee2mqtt.io"},"payload_off":false,"payload_on":true,"state_topic":"zigbee2mqtt/cuinaLlumTaulell","unique_id":"0x0c4314fffe0f8ab6_update_available_zigbee2mqtt","value_template":"{{ value_json['update']['state'] == \"available\" }}"}

homeassistant/select/0x0c4314fffe0f8ab6/effect/config

{"availability":[{"topic":"zigbee2mqtt/bridge/state","value_template":"{{ value_json.state }}"}],"command_topic":"zigbee2mqtt/cuinaLlumTaulell/set/effect","device":{"identifiers":["zigbee2mqtt_0x0c4314fffe0f8ab6"],"manufacturer":"IKEA","model":"TRADFRI driver for wireless control (30 watt) (ICPSHC24-30EU-IL-1)","name":"cuinaLlumTaulell","sw_version":"2.3.086","via_device":"zigbee2mqtt_bridge_0x00124b0012c38fda"},"enabled_by_default":false,"icon":"mdi:palette","name":"Effect","object_id":"cuinallumtaulell_effect","options":["blink","breathe","okay","channel_change","finish_effect","stop_effect"],"origin":{"name":"Zigbee2MQTT","sw":"1.36.0","url":"https://www.zigbee2mqtt.io"},"unique_id":"0x0c4314fffe0f8ab6_effect_zigbee2mqtt"}

homeassistant/select/0x0c4314fffe0f8ab6/power_on_behavior/config

{"availability":[{"topic":"zigbee2mqtt/bridge/state","value_template":"{{ value_json.state }}"}],"command_topic":"zigbee2mqtt/cuinaLlumTaulell/set/power_on_behavior","device":{"identifiers":["zigbee2mqtt_0x0c4314fffe0f8ab6"],"manufacturer":"IKEA","model":"TRADFRI driver for wireless control (30 watt) (ICPSHC24-30EU-IL-1)","name":"cuinaLlumTaulell","sw_version":"2.3.086","via_device":"zigbee2mqtt_bridge_0x00124b0012c38fda"},"enabled_by_default":true,"entity_category":"config","icon":"mdi:power-settings","name":"Power-on behavior","object_id":"cuinallumtaulell_power_on_behavior","options":["off","on","toggle","previous"],"origin":{"name":"Zigbee2MQTT","sw":"1.36.0","url":"https://www.zigbee2mqtt.io"},"state_topic":"zigbee2mqtt/cuinaLlumTaulell","unique_id":"0x0c4314fffe0f8ab6_power_on_behavior_zigbee2mqtt","value_template":"{{ value_json.power_on_behavior }}"}

homeassistant/update/0x0c4314fffe0f8ab6/update/config

{"availability":[{"topic":"zigbee2mqtt/bridge/state","value_template":"{{ value_json.state }}"}],"command_topic":"zigbee2mqtt/bridge/request/device/ota_update/update","device":{"identifiers":["zigbee2mqtt_0x0c4314fffe0f8ab6"],"manufacturer":"IKEA","model":"TRADFRI driver for wireless control (30 watt) (ICPSHC24-30EU-IL-1)","name":"cuinaLlumTaulell","sw_version":"2.3.086","via_device":"zigbee2mqtt_bridge_0x00124b0012c38fda"},"device_class":"firmware","entity_category":"config","entity_picture":"https://github.com/Koenkk/zigbee2mqtt/raw/master/images/logo.png","json_attributes_template":"{\"in_progress\": {{ iif(value_json['update']['state'] == 'updating', 'true', 'false') }} }","json_attributes_topic":"zigbee2mqtt/cuinaLlumTaulell","latest_version_template":"{{ value_json['update']['latest_version'] }}","latest_version_topic":"zigbee2mqtt/cuinaLlumTaulell","name":null,"object_id":"cuinallumtaulell","origin":{"name":"Zigbee2MQTT","sw":"1.36.0","url":"https://www.zigbee2mqtt.io"},"payload_install":"{\"id\": \"0x0c4314fffe0f8ab6\"}","state_topic":"zigbee2mqtt/cuinaLlumTaulell","unique_id":"0x0c4314fffe0f8ab6_update_zigbee2mqtt","value_template":"{{ value_json['update']['installed_version'] }}"}

homeassistant/light/0x0c4314fffe0f8ab6/light/config

{"availability":[{"topic":"zigbee2mqtt/bridge/state","value_template":"{{ value_json.state }}"}],"brightness":true,"brightness_scale":254,"command_topic":"zigbee2mqtt/cuinaLlumTaulell/set","device":{"identifiers":["zigbee2mqtt_0x0c4314fffe0f8ab6"],"manufacturer":"IKEA","model":"TRADFRI driver for wireless control (30 watt) (ICPSHC24-30EU-IL-1)","name":"cuinaLlumTaulell","sw_version":"2.3.086","via_device":"zigbee2mqtt_bridge_0x00124b0012c38fda"},"effect":true,"effect_list":["blink","breathe","okay","channel_change","finish_effect","stop_effect"],"name":null,"object_id":"cuinallumtaulell","origin":{"name":"Zigbee2MQTT","sw":"1.36.0","url":"https://www.zigbee2mqtt.io"},"schema":"json","state_topic":"zigbee2mqtt/cuinaLlumTaulell","unique_id":"0x0c4314fffe0f8ab6_light_zigbee2mqtt"}

homeassistant/device_automation/0x0c4314fffe0f8ab6/action_off/config

{"automation_type":"trigger","device":{"identifiers":["zigbee2mqtt_0x0c4314fffe0f8ab6"],"manufacturer":"IKEA","model":"TRADFRI driver for wireless control (30 watt) (ICPSHC24-30EU-IL-1)","name":"cuinaLlumTaulell","sw_version":"2.3.086"},"origin":{"name":"Zigbee2MQTT","sw":"1.34.0","url":"https://www.zigbee2mqtt.io"},"payload":"off","subtype":"off","topic":"zigbee2mqtt/cuinaLlumTaulell/action","type":"action"}

homeassistant/device_automation/0x0c4314fffe0f8ab6/action_on/config

{"automation_type":"trigger","device":{"identifiers":["zigbee2mqtt_0x0c4314fffe0f8ab6"],"manufacturer":"IKEA","model":"TRADFRI driver for wireless control (30 watt) (ICPSHC24-30EU-IL-1)","name":"cuinaLlumTaulell","sw_version":"2.3.086"},"origin":{"name":"Zigbee2MQTT","sw":"1.34.0","url":"https://www.zigbee2mqtt.io"},"payload":"on","subtype":"on","topic":"zigbee2mqtt/cuinaLlumTaulell/action","type":"action"}

@enboig: are you still having issues? I tried to reproduce this by publishing your configuration info so I have your exact device config, adding the thing in openHAB, linking a switch channel, and then publishing a state for the device (I just copied the state from one of my own zigbee2mqtt lights). It’s properly showing OFF with no %. I am running openHAB 4.3.0-SNAPSHOT, and also this PR, but neither of those should impact unit handling.

I am having exactly the same WARN Cannel mqtt:…:brightness not supported message with a hue light bulb. How did you fix it?
Do I have to add the channels manually?