How to implement DIM light (ElkoEP) operated over web curl

Hi everybody, I’m just quite a new boy in HA world. Using RasPi 3B+, Hass.io, Sonoff Tasmota. Almost everything is working. Now I’m facing a new challenge to use ELKO EP devices (https://www.elkoep.com/wireless-rf-control) which are not supported by HA yet. Is it this right thread here to ask about developing questions please?

I have several LED switches, which are controlled over LAN. Here is a sample how I can control them from HA:

- platform: command_line
      switches:
        elkoep_led_lab:
          command_on: /usr/bin/curl -X PUT http://192.168.90.10/api/devices/33633 -d'{"brightness":100}'
          command_off: /usr/bin/curl -X PUT http://192.168.90.10/api/devices/33633 -d'{"brightness":0}'
          command_state: /usr/bin/curl -X GET http://192.168.90.10/api/devices/33633/state
          value_template: '{{value_json.brightness != 0}}'
          friendly_name: "LED LAB"

Currently I’m able only turn it on and of in preset brightness. I wish to have some dim able function using brightness values. Any ideas how to implement this? Maybe from some different products?

Check out the documentation for template lights. If you have any further questions let us know :slightly_smiling_face:

This topic might be useful.

I did RTFM before my post :slight_smile:

So I tried this:

light:
  - platform: template
    lights:
      dim_lights:
        friendly_name: "DIM Light"
        level_template: "{{ sensor.theater_brightness.attributes.lux|int }}"
        value_template: "{{ sensor.theater_brightness.attributes.lux|int > 0 }}"
        turn_on:
          service: script.1561491006950
        turn_off:
          service: script.1561491077045
        set_level:
          service: script.theater_lights_level
          data_template:
            brightness: "{{ brightness }}"

and in scripts

'1561491006950':
  alias: dim_on
  sequence:
  - data:
      entity_id: switch.elkoep_led_lab
    service: switch.turn_on

'1561491077045':
  alias: dim_off
  sequence:
  - data:
      entity_id: switch.elkoep_led_lab
    service: switch.turn_off

But this is probably not good approach. Not only because it is not working :slight_smile: I wish to implement it as a new platform. I think it should be very similar as other IOT devices.

Now I found you also pointing into some topic - going to study this topic, thanks

This is partly new to me, so I don’t have a ready made example for you. We can figure it out together though. I think you’ll need shell commands instead of a command line switch. A switch only allows on & off, so no brightness setting. You’ll want to replace the command line switch with a light template.

So shell commands probably something like this:

shell_command:
  led_on: /usr/bin/curl -X PUT http://192.168.90.10/api/devices/33633 -d'{"brightness":100}'
  led_off: /usr/bin/curl -X PUT http://192.168.90.10/api/devices/33633 -d'{"brightness":0}'
  led_brightness: /usr/bin/curl -X PUT http://192.168.90.10/api/devices/33633 -d'{"brightness:"{{bri}}}'

You’ll have to try if they work for you like this. I’m not sure about the quotes and curlies.

Then a template light:

- platform: template
    lights:
      elkoep_led:
        friendly_name: "Elkoep led light"
        turn_on:
          service: shell_command.led_on
        turn_off:
          service: shell_command.led_off
        set_level:
          service: shell_command.led_brightness
          data_template:
            bri: "{{ brightness | int }}"

Edit: corrected some small typos.

Thank you very much Emphyrio! But I’m still not able to transfer brightness parameter.

shell_command working. But only in first two cases. Last one with parameter not. I’m trying to run it from Developer Tolls / Services and as DATA I put 100. I also tried this:


led_brightness: /usr/bin/curl -X PUT http://192.168.90.10/api/devices/33633 -d'{{bri}}'

and as data I used: {“brightness”: 100} but still no sucess.

I also tried this and this is working.


switch:
    - platform: rest
      name: "ElkoLED"
      resource: http://192.168.90.10/api/devices/33633
      method: put
      body_on: '{"brightness": 100}'
      body_off: '{"brightness": 0}'
      verify_ssl: false

But I still do not know to use brightness as a variable value.

I didn’t realise the shell command was a REST command :blush:

Then you can try (in configuration.yaml):

rest_command:
  led_brightness:
    url: http://192.168.90.10/api/devices/33633 -d'{"brightness:"{{bri}}}'

In your template light, the last part can be:

        set_level:
          - service: rest_command.led_brightness
            data_template:
              bri: >
                {{ (brightness /255*100) | int }}

That last calculation is for converting the default brightness scale (0-255) to a percentage scale (0-100). I’m not sure about the curlies and quotes, don’t have any experience with such a URL construct. You might need to escape some of those characters.

Still no sucess, this is in error log:

Error 400 on call http://192.168.90.10/api/devices/33633%20-d'%7B%22brightness:%2213%7D'

Any idea? Thanks a lot!

Finally after several hours of learning, testing, restarting HA I found partially working configuration.

I can turn ON / OFF and set Brightess from UI.

shell_command:
  led_on: /usr/bin/curl -X PUT http://192.168.90.10/api/devices/33633 -d'{"brightness":100}'
  led_off: /usr/bin/curl -X PUT http://192.168.90.10/api/devices/33633 -d'{"brightness":0}'
  
rest_command:
   led_brightness:
     url: http://192.168.90.10/api/devices/33633
     method: PUT
     payload: '{"brightness": {{ jas }} }'
     content_type:  'application/json; charset=utf-8'
     verify_ssl: false
     

light:
  - platform: template
    lights:
      elkoep_led:
        friendly_name: "Elkoep led light"
        # value_template: '{{value_json.brightness}}' - WHAT TO TYPE HERE?
        # level_template: "{{value_json.brightness | int }}" - WHAT TO TYPE HERE?
        turn_on:
          service: shell_command.led_on
        turn_off:
          service: shell_command.led_off
        set_level:
          - service: rest_command.led_brightness
            data_template:
              jas: >
                {{ (brightness /255*100) | int }}

I wish to also see status of light - if it is on or off and which brightness.

This is how I can read status from device as REST sensor

# Sensors
sensor:
  # RESTful senzor test
  - platform: rest
    name: JSON LAB
    json_attributes:
      - automat
      - brightness
    resource: http://192.168.90.10/api/devices/33633/state
    value_template: '{{ value_json.brightness }}'
    verify_ssl: false
  - platform: template
    sensors:
      auto:
        friendly_name: 'Automat'
        value_template: '{{ states.sensor.json_lab.attributes["automat"] }}'
      bright:
        friendly_name: 'Jas'
        value_template: '{{ states.sensor.json_lab.attributes["brightness"] }}'

But I do not know how to implement this into Light template - value and level template. I’m still little bit confusing in templates use.

Thank you

I create solution which is working now, but I’m not sure if this is best approach. Please check

More here How to configure Dim Light properly - looking for best approach