Shelly Dimmer with MQTT

This is probably obvious to most, but I couldn’t find it elsewhere or in the shelly documentation. You can access the state of a second switch connected to the dimmer by creating the following binary sensor in configuration.yaml

binary_sensor:
 - platform: mqtt
    name: "test dimmer"
    state_topic: "shellies/shellydimmer-<id of your dimmer>/input/1"
    payload_on: "1"
    payload_off: "0" 
1 Like

Hey there. I stumbled upon your post and would like to thank you for generally making my shelly dimmer work in Home Assistant. On my own and with the provided documentation about MQTT lights, I did not manage to get the dimming slider working.

I have a question though and Im hoping you could help me out here. I would totally understand if you dont.

My lights are controlled by a Homematic Switch. It turns them on and off either through the Homematic interface (or Home Assistant) or through a physical switch. I also have a shelly dimmer to add dimming functionality. With the code you provided I have a couple of inconveniences I would like to get rid off:

I want the shelly to not send on/off commands at all. Right now, when I move the slider to the left. The shelly turns off. The relay from the homematic switch thinks the lights are still on though. So when I press the physical light button, the button thinks the light is on still. Only after pressing the button twice (homematic relay off, homematic relay on again) the lights will turn on again. Same story the other way around: when the homematic switch is off through either the physical switch or the interface, and I move the slider to the right, the homematic system thinks the switch is still off. So in order to switch off the light with the physical switch, I have to press twice again (relay on, relay off).

Is it somehow possible to configure the slider in a way that it only dims? I was thinking about a slider that sends a retained brightness message to the shelly switch via MQTT and only when I activate the Homematic Switch the shelly dimmer will dim accordingly. I tested it with MQTT.fx and know that its working. I just dont know how to implement this slider into home assistant, because every configuration in MQTT light somehow requires these on/off topics.

Best
Wong

Hi,

I’m trying to use your code for my Shelly2 dimmer. Should the code be under “sensor”, light or “switch”? When I do a config check the message says "Invalid config for [light.mqtt]: [state_template] is an invalid option for [light.mqtt]. Check: light.mqtt->state_template. (See ?, line ?).

Thanks for your help.

GUYS, this topic is really amazing, i was looking for a working mqtt command and this thing on this topic works like a charm!!! Thanks a lot for that.

light:
  - platform: mqtt
    schema: template
    name:  Shelly Dimmer
    state_topic: "shellies/SHELLY1_MQTT/light/0/status"
    state_template: '{% if value_json.ison %} on {% else %} off {% endif %}'
    command_topic: "shellies/SHELLY1_MQTT/light/0/set"
    command_on_template: '{"turn": "on"{% if brightness is defined %}, "brightness": {{(brightness | float * 0.3882 + 1) | round(0)}}{% endif %}}'
    command_off_template: '{"turn": "off"}'
    brightness_template: '{{ (value_json.brightness | float * 2.55) | round(0) }}'

Another question,

When i use my momentary regular wall switch, i will all the time when pressed on UP or DOWN to turn ON the light, it should be brightness on 100 percent. It state now the home assistant status if there the brightness 70% as example.

On the Shelly APP button type is at this moment set to Edge Mode. Should i change that?

By default HA is not responsible for dimmer brightness after turn on.
The dimmer starts with intensity used previously. If you quickly double-click on the momentary button, it will start with 100%.
If you don’t like this behaviour you can likely create an automation which will be triggered by turning light off and will set brightness of light to 100% without turning it on. I wrote “likely” because I haven’t checked it with a dimmer yet. However this method works with another shelly device: rgbw2.

BTW don’t ask how to do that in HA - I’m not familiar with HA automations. I’m using NodeRed for that.

If you simply want it to always turn on at 100%, use an automation in HA to detect when the light is switched on and then set the brightness. I do this for one of my light bulbs (not shelly):

- alias: Set Office Ceiling Light to 100% when switched on
  trigger:
    platform: state
    entity_id: light.office_ceiling_light
    to: 'on'
  action:
    service: light.turn_on
    entity_id: light.office_ceiling_light
    data:
      brightness_pct: 100
      color_temp: 250

Or you could try this:

Very very thanks man, added this one on my automation and works like a charm!!!