I am mapping a Light RGB platform into an LED BLE device (no supported by the existing integration)
The problem I have is that I get each R,G,B update in different “outputs” so each color update gets 3 times bigger and they just do not come through.
Is there a way to group the RBG light updates into one array of those values?
this is my existing config:
esphome:
includes:
- common/bluetooth-virtual-light.h
###############################
########## BLUETOOTH #########
#############################
# bluetooth_proxy:
# active: true
# esp32_ble_tracker:
# scan_parameters:
# # We currently use the defaults to ensure Bluetooth
# # can co-exist with WiFi In the future we may be able to
# # enable the built-in coexistence logic in ESP-IDF
# active: false
binary_sensor:
- platform: template
name: "Led BLE Connected"
id: led_ble_connected_sensor
ble_client:
- mac_address: ${bluetooth_virtual_light_mac}
id: my_ble_client
on_connect:
then:
- lambda: |-
ESP_LOGD("virtual_ble_light", "Connected to BLE device");
- binary_sensor.template.publish:
id: led_ble_connected_sensor
state: ON
on_disconnect:
then:
- lambda: |-
ESP_LOGD("virtual_ble_light", "Disconnected to BLE device");
- binary_sensor.template.publish:
id: led_ble_connected_sensor
state: OFF
light:
- platform: rgb
name: BLE LED
red: red_channel_output
green: green_channel_output
blue: blue_channel_output
default_transition_length: 0s
on_turn_on:
- lambda: |-
id(led_ble_on_off_switch).turn_on();
on_turn_off:
- lambda: |-
id(led_ble_on_off_switch).turn_off();
globals:
- id: red_value
type: float
initial_value: "0.00"
# restore_value: true
- id: green_value
type: float
initial_value: "0.00"
# restore_value: true
- id: blue_value
type: float
initial_value: "0.00"
# restore_value: true
output:
- platform: template
id: red_channel_output
type: float
write_action:
- lambda: |-
char buf[30];
id(red_value) = state;
sprintf(buf, "red_channel_output=%.2f", id(red_value));
ESP_LOGI("virtual_ble_light", buf);
- ble_client.ble_write:
id: my_ble_client
service_uuid: FFE0
characteristic_uuid: FFE1
value: !lambda |-
return bvl_createColorUpdateArray(id(red_value), id(green_value), id(blue_value));
- platform: template
id: green_channel_output
type: float
write_action:
- lambda: |-
char buf[30];
id(green_value) = state;
sprintf(buf, "green_channel_output=%.2f", id(green_value));
ESP_LOGI("virtual_ble_light", buf);
- ble_client.ble_write:
id: my_ble_client
service_uuid: FFE0
characteristic_uuid: FFE1
value: !lambda |-
return bvl_createColorUpdateArray(id(red_value), id(green_value), id(blue_value));
- platform: template
id: blue_channel_output
type: float
write_action:
- lambda: |-
char buf[30];
id(blue_value) = state;
sprintf(buf, "blue_channel_output=%.2f", id(blue_value));
ESP_LOGI("virtual_ble_light", buf);
- ble_client.ble_write:
id: my_ble_client
service_uuid: FFE0
characteristic_uuid: FFE1
value: !lambda |-
return bvl_createColorUpdateArray(id(red_value), id(green_value), id(blue_value));
switch:
- platform: ble_client
ble_client_id: my_ble_client
name: "Enable Bluetooth"
internal: true
- platform: template
id: led_ble_on_off_switch
name: "Turn On Led"
turn_on_action:
- ble_client.ble_write:
id: my_ble_client
service_uuid: FFE0
characteristic_uuid: FFE1
value: [ 126, 255, 4, 1, 255, 255, 255, 255, 239 ]
- lambda: |-
ESP_LOGI("virtual_ble_light", "SEND MESSAGE TO TURN ON");
turn_off_action:
- ble_client.ble_write:
id: my_ble_client
service_uuid: FFE0
characteristic_uuid: FFE1
value: [ 126, 255, 4, 0, 255, 255, 255, 255, 239 ]
- lambda: |-
ESP_LOGI("virtual_ble_light", "SEND MESSAGE TO TURN OFF");