I have a setup where i receive a hex string from a BLE device. The hex string aa:aa:aa:aa (12 times) i want to send to HA.
text_sensor:
- platform: homeassistant
id: ble_raw_reading
name: Ble Raw Reading
entity_id: input_text.ble_raw_reading
- platform: ble_client
id: ${ble_id_prefix}_reading_data
name: ${ble_name_prefix} reading data
internal: true
ble_client_id: ble_client_${ble_id_prefix}
service_uuid: ${ble_recieve_service_uuid}
characteristic_uuid: ${ble_recieve_characteristic_uuid}
notify: true
update_interval: never
on_notify:
then:
lambda: |-
auto tempvar = format_hex_pretty((uint8_t *) x.c_str(), x.size());
ESP_LOGD("${blueriiot_id_prefix}", "%s", format_hex_pretty((uint8_t *) x.c_str(), x.size()).c_str());
id(ble_raw_reading).publish_state(tempvar);
The log output on notify is this:
[21:22:55][V][ble_text_sensor:096]: [Ble reading data] ESP_GATTC_NOTIFY_EVT: handle=0x14, value=0x33
[21:22:55][V][text_sensor:016]: 'Ble reading data': Received new state 3\x9eama\x9d
[21:22:55][D][text_sensor:067]: 'Ble reading data': Sending state '3\x9eama\x9d '
[21:22:55][D][ble_client:153]: 33.9E.07.6D.07.9D.09.00.00.25.0E.15 (12)
[21:22:55][V][text_sensor:016]: 'Ble Raw Reading': Received new state 33.9E.07.6D.07.9D.09.00.00.25.0E.15 (12)
[21:22:55][D][text_sensor:067]: 'Ble Raw Reading': Sending state '33.9E.07.6D.07.9D.09.00.00.25.0E.15 (12)'
[21:22:55][VV][api.service:174]: send_text_sensor_state_response: TextSensorStateResponse {
key: 2237994003
state: '33.9E.07.6D.07.9D.09.00.00.25.0E.15 (12)'
missing_state: NO
}
When I update the state of the input_text.ble_raw_reading using development tools the new state is received in ESPHome.
[21:33:17][VV][api.service:507]: on_home_assistant_state_response: HomeAssistantStateResponse {
entity_id: 'input_text.ble_raw_reading'
state: 'manual-update'
attribute: ''
}
[21:33:17][D][homeassistant.text_sensor:017]: 'input_text.ble_raw_reading': Got state 'manual-update'
[21:33:17][V][text_sensor:016]: 'Ble Raw Reading': Received new state manual-update
[21:33:17][D][text_sensor:067]: 'Ble Raw Reading': Sending state 'manual-update'
The other way around i cannot get to work. I am missing something?
(also found a post that uses MQTT to send the state of the text_sensor to HA, that looks like a detour and i would like to avoid that if possible).
When i use the following config, HA creates a sensor.ble_raw_reading instead of a helper (input_text).
text_sensor:
- platform: template
id: ble_raw_reading
name: Ble Raw Reading
#entity_id: input_text.ble_raw_reading
How can i send the new state from ESPHome to HA using a text_sensor?