Hello, I have been trying to create a custom light template to control my Govee lights via API calls.
the problem is that Govee API only takes a RGB number using a formula : The instance colorRgb
can change light color,you can get RGB number follow this formula ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | ((b & 0xFF) << 0)
but set_rgb only takes R,G,B numbers.
How do I implement it?
Here is my code:
platform: template
lights:
heater_light:
friendly_name: "Heater Light"
unique_id: heater_light
value_template: "{{ is_state('binary_sensor.heater_nightlight_toggle', 'on') }}"
level_template: "{{ (states('sensor.heater_brightness') | int * 255 / 100) | int }}"
availability_template: "{{ is_state('binary_sensor.heater_online', 'on') }}"
rgb_template: "({{ states('sensor.heater_color_rgb').split(',')[0] | int}} , {{ states('sensor.heater_color_rgb').split(',')[1] | int }}, {{ states('sensor.heater_color_rgb').split(',')[2] | int }})"
turn_on:
service: rest_command.set_heater_light_toggle
data:
value: 1
turn_off:
service: rest_command.set_heater_light_toggle
data:
value: 0
set_level:
service: rest_command.set_heater_light_brightness
data:
value: "{{ (brightness * 100 / 255) | int }}"
set_rgb:
service: rest_command.set_govee_light_color
data:
rgbw_color:
- "{{ r }}"
- "{{ g }}"
- "{{ b }}"
- "{{ w }}"
all the other features work but not the Set RGB.
here is my rest command:
set_govee_light_color:
url: "https://openapi.api.govee.com/router/api/v1/device/control"
method: "post"
headers:
Content-Type: "application/json"
Govee-API-Key: !secret govee_api_key
payload: '{"requestId": "uuid", "payload": {"sku": "H7131", "device": "7A:67:D4:AD:FC:F5:69:7B", "capability": {"type": "devices.capabilities.color_setting", "instance": "colorRgb", "value": "{{ rgb_number }}"}}}'
now my question is how do i convert the R,G,B values to RGB number and then pass it to the API?