Odd problem, I want to turn on a light with set brightness, but it doesn't work

I have set up a light with a restful api.
I can turn it on and off, and adjust brightness from the interface.
But if I try and turn the light on with a set brightness i Node-Red it fails to set the brightness?

My ‘light’ is a magicmirror, there was an integration to it, but that has died.
So I wanted to set up my own ‘integration’ via a RESTful(ish) API to the module called Remote-control in MagicMirror.

First of I’ve created three rest_commands:

turn_on_bathroom_monitor:
  url: "http://1.2.3.4:8080/api/monitor/on?apiKey=xxx"
  method: get

turn_off_bathroom_monitor:
  url: "http://1.2.3.4:8080/api/monitor/off?apiKey=xxx"
  method: get

set_bathroom_monitor_brightness:
  url: "http://1.2.3.4:8080/api/brightness/{{ brightness }}?apiKey=xxx"
  method: get

Then I made two sensors

- platform: rest
  name: Bathroom Monitor state
  resource: "http://1.2.3.4:8080/api/monitor/?apiKey=xxx"
  method: GET
  value_template: "{{ value_json.monitor }}"
- platform: rest
  name: Bathroom Monitor brightness
  resource: "http://1.2.3.4:8080/api/brightness/?apiKey=xxx"
  method: GET
  value_template: "{{ (value_json.result | float * 2.55) | round(0) }}"
  scan_interval: 20

So now I can set values and read values.
I then made a light:

    bathroom_monitor:
      friendly_name: "MagicMirror Bathroom Monitor"
      unique_id: "e2d0359d-aafe-4140-a234-f59054e93f30"
      turn_on:
        - action: rest_command.turn_on_bathroom_monitor
        - delay: 1
        - action: homeassistant.update_entity
          data:
            entity_id: sensor.bathroom_monitor
      turn_off:
        - action: rest_command.turn_off_bathroom_monitor
        - delay: 1
        - action: homeassistant.update_entity
          data:
            entity_id: sensor.bathroom_monitor
      level_template: "{{ states('sensor.bathroom_monitor_brightness') | int }}"
      set_level:
        - action: rest_command.set_bathroom_monitor_brightness
          data_template:
            brightness: "{{ (brightness / 2.55) | int }}"
        - delay: 1
        - action: homeassistant.update_entity
          data:
            entity_id: sensor.bathroom_monitor_brightness
      icon_template: >-
        mdi:mirror-rectangle

Thanks to @tom_l I got the long delay in updates of the state fixed.
So now I can control the monitor, turn it on/off and brightness.
Just what I wanted.

But if I turn the ‘light’ on in Node-red with a JSON data field with brightness, it doesn’t work? If I omit the brightness it works.


When I look in developer tools, the light is reported like this:

supported_color_modes:
  - brightness
color_mode: null
brightness: null
icon: mdi:mirror-rectangle
friendly_name: MagicMirror Bathroom Monitor
supported_features: 0

So is it that it doesn’t support brightness_pct, but only brightness?

Use two action nodes one right after another. The first calls light turn on, the second calls light turn on with brightness data.

Yeah, I know, but shouldn’t I be able to do that as one step? Anyways, thanks!

This is a known issue with some light bulbs. It’s caused by the bulb itself and not anything ha/nr is doing.