Shelly Dimmer with MQTT

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!!!

Hello!! I have a SHELLY DUO that works for me with this code but I can’t change the temperature. The DUO has warm white and cool white. Can you help me?

This any good ?

Seems like this is not supported anymore, removed it and still works as expected!
Thanks!

Where did you read from that state_template is not supported?

In fact VSC marks it as unsupported. But the attribude exists in documentation. As well as state_topic which is accepted by VSC. Actually how could the HA be informed about on/off state otherwise?

Property state_template is not allowed.yaml-schema: http://schemas.home-assistant.io/integration-light

Where this text you took from?what version of HA? I have 0.118.5 and has no such msg in logs.

Again: how HA could retrieve state of entity without this attribute?

Mmh am on 0.118 as well.
But the error is reported by the vscode plugin, seems if I just run HA with it, its fine…

then it seems to be vsc issue only, as I said before

Yes thanks anyway!

Hi everyone,

I started over the weekend to move all my Shellies to MQTT. So far no issues, but I definitely have trouble to get my Dimmer to work. The Dimmer itself works fine since month with the integration.

image

What am I doing wrong? (I’m not a hack in Yaml, btw)

Cheers

mqtt:
  switch: # including all other relays such as Shelly25 and Shelly1

  light:
    - unique_id: mq_kitchen_light_dimmer
      name: mq Kitchen Light Dimmer
      schema: template
      state_topic: "shellies/shellydimmer-<my_ID>/light/0/status"
      state_template: '{% if value_json.ison %} on {% else %} off {% endif %}'
      command_topic: "shellies/shellydimmer-<my_ID>/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 | multiply(2.55) | round(0) }}'

Now that there’s an official Shelly integration, what’s the motivation to use MQTT?

I am using the integration for the dimmer and for an RGBWW. However the response time on my shelly25s and Shelly1s was way too long to use them in automations (eg. Switch a Shelly and turn on a light on a smart plug as well). Acc. my understanding the integration is polling (not adjustable) and mqtt is using push. At this point there is no other way as using mqtt for the relays, but in general I would like to have them setup all in the same way if possible.

Here is my configuration of the dimmer.

  mqtt:
    light:
      - name: "Bedroom 1"
        schema: template
        state_topic: "shellies/light-bedroom-ceiling/light/0/status"
        availability_topic: "shellies/light-bedroom-ceiling/online"
        command_topic: "shellies/light-bedroom-ceiling/light/0/set"
        state_template: "{% if value_json.ison %} on {% else %} off {% endif %}"
        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) }}"
        payload_available: "true"
        payload_not_available: "false"
        qos: 1
        retain: false
        optimistic: false

I can see a few differences. But Cannot say those are crucial

  1. state_template and brightness_template are enclosed with double quotes, while you are using single quotes.
  2. You are using unique_id. Check others entities declaration or logs. Maybe you did copy&paste error, having 2 entities with the same identifier?
  3. Optimistic setting (you are using default which equals true). For devices responding immediately false is better IMO. Also maybe there is a glitch in implementation. Worth to check.

Other than that it looks pretty the same (or differences are not important).

3 keywords: stability, reliability, and transparency.
MQTT is (potentially or not) way better in all those aspects compared to native integration.

1 Like

Thanks a lot … I will try that and give feedback. One question:
How your topics are linking into the correct device or in other words, how does mqtt know what Shelly ID to “talk” to?

You have:

        state_topic: "shellies/light-bedroom-ceiling/light/0/status"
        availability_topic: "shellies/light-bedroom-ceiling/online"
        command_topic: "shellies/light-bedroom-ceiling/light/0/set"

and I have (which includes the device ID:

      state_topic: "shellies/shellydimmer-<my_ID>/light/0/status"
      command_topic: "shellies/shellydimmer-<my_ID>/light/0/set"

Sorry if that is a rookie question :slight_smile:

Thanks again

Ok … I changed to:

    - name: "My Not Working Dimmer"
      schema: template
      state_topic: "shellies/shellydimmer-3C6105E42C4D/light/0/status"
      availability_topic: "shellies/shellydimmer-3C6105E42C4D/online"
      command_topic: "shellies/shellydimmer-3C6105E42C4D/light/0/set"
      state_template: "{% if value_json.ison %} on {% else %} off {% endif %}"
      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) }}"
      payload_available: "true"
      payload_not_available: "false"
      qos: 1
      retain: false
      optimistic: false

I have changed the name, to make sure to have a new entity (shouldn’t matter but just in case). Still not working. Communication seems to work, so I wouldn’t expect a settings issue?

According to the integration page, it’s local push, not poll.

Can you elaborate? I don’t have any stability or reliability problems with the integration (not entirely sure what you mean by transparency), and I believe that in most cases adding another layer would make these worse, not better.