Custom MQTT Device Set - ESP32

Dear All,

Apologies, I reviewed all topics and might be I’m a little bit processing slower and harder the information, but I did not find what I needed to be done.

I’m using OpenHAB, but I’m very curious about Home Assistant and I decided to setup a parallel server to be able to test it because I might consider to change. I have a custom-built LED Strip controller based on ESP32 where I use MQTT.

I’m using three topics to control this:
command_topic: /esp05/led/set
state_topic: /esp05/led

… and I have a third topic where I read out the real values of the settings from ESP32 and send them back to automation - as a string:
state_topic: /esp05/globaldata

I receive the “globaldata” information in this JSON structure:

{
  "state": "ON",
  "brightness": 79,
  "effect": "kissge4",
  "color": {
    "r": 89,
    "g": 0,
    "b": 40
  }
}

Regarding to send my commands to the command topic, I’m also using simple JSON:

{ "state": "ON"} or {"state": "OFF"}
{"brightness":79}
{"transition":84}
{"color" : {"r": 89, "g" : 0, "b":87}
{"effect":"confetti"}

Could you please show me a guide where should I really start if I would like to set this custom MQTT device in Home Assistant and I would like to control it like this?

  • On / Off
  • Set Brightness, Transition, Color or Set Effect

Much appreciate your guide and help.
Kind Regards,
Gergely

Bottom-Up, this is your starting point:

Thank you Koyig!

I can see my friend will be the “json schema”.
One last question, how can I setup and send the “speed” of my animations - transition. I do not see any possibility there. I can create a slider in OpenHAB for anything and I need to define it, but here I just can see on/off, brightness, rgb and effect.

Much appreciated,
Gergely

Transitions are integral to an HA light.
If you set one in a light.turn_on action, a json like described below will be sent to the command topic, to be managed by the device.

Thank you very much!
I do not see “transitions” in the command topic, even with the “template” schema.
With “template”, the “state” is also not working for me, there is no feedback visible from the device with these settings.

mqtt:
  - light:
      schema: template
      unique_id: nappali_led
      name: "Nappali LED csík"
      effect_list:
      - animations
      - beatwave
      - blendwave
      - blur
      - bpm
      - candy cane
      - confetti
      command_topic: "esp01/led/set"
      state_topic: "esp01/led"
      command_on_template: >
        {"state": "ON"
        {%- if brightness is defined -%}
        , "brightness": {{ brightness }}
        {%- endif -%}
        {%- if red is defined and green is defined and blue is defined -%}
        , "color": {"r":{{ red }}, "g":{{ green }}, "b":{{ blue }} }
        {%- endif -%}
        {%- if effect is defined -%}
        , "effect": "{{ effect }}"
        {%- endif -%}
        {%- if transition is defined -%}
        , "transition": "{{ transition }}"
        {%- endif -%}
        }
      command_off_template: '{"state": "OFF"}'
      state_template: '{{ value_json.state }}'
      brightness_template: '{{ value_json.brightness }}'
      red_template: '{{ value_json.color.r }}'
      green_template: '{{ value_json.color.g }}'
      blue_template: '{{ value_json.color.b }}'
      effect_template: '{{ value_json.effect }}'

… but if I use “json schema”, works good, but no transition. :frowning:

Many thanks,
Gergo

If you use JSON, the transition will be in the payload sent to the device if you specify one in the action.

Hello Koyig,

Thank you very much!
Yes, I know, I looked for the payload and I did not find the transition. I just need to figure out how I can specify a transition action… :slight_smile:
I can easily set up a slide bar (for transition) in OpenHAB and define the command topic and the JSON value, and once I move it from 0-100% the payload is always generating and sending out the value to the device. This kind of thing I would like to achieve. :slight_smile:

Kind Regards,
Gergo

OK, I found a solution via number.mqtt:

  - number:
      command_topic: "esp01/led/set"
      unique_id: nappali_led_transition
      name: "Nappali LED Transition"
      command_template: '{"transition": {{ value }} }'
      min: 0
      max: 255
      mode: slider

The only remaining thing is to change the values on GUI from 0-255 to 0-100 as percentage :slight_smile: