mirror of
https://github.com/esphome/esphome.git
synced 2025-09-02 03:12:20 +01:00
Add attribute support to Home Assistant sensors (#1770)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
@@ -49,6 +49,7 @@ class CustomNativeAPI : public Component, public CustomAPIDevice {
|
||||
register_service(&CustomNativeAPI::on_start_dryer, "start_dryer", {"value"});
|
||||
register_service(&CustomNativeAPI::on_many_values, "many_values", {"bool", "int", "float", "str1", "str2"});
|
||||
subscribe_homeassistant_state(&CustomNativeAPI::on_light_state, "light.my_light");
|
||||
subscribe_homeassistant_state(&CustomNativeAPI::on_brightness_state, "light.my_light", "brightness");
|
||||
}
|
||||
|
||||
void on_hello_world() { ESP_LOGD("custom_api", "Hello World from native API service!"); }
|
||||
@@ -69,4 +70,5 @@ class CustomNativeAPI : public Component, public CustomAPIDevice {
|
||||
call_homeassistant_service("homeassistant.restart");
|
||||
}
|
||||
void on_light_state(std::string state) { ESP_LOGD("custom_api", "Got state %s", state.c_str()); }
|
||||
void on_brightness_state(std::string state) { ESP_LOGD("custom_api", "Got attribute state %s", state.c_str()); }
|
||||
};
|
||||
|
@@ -63,6 +63,10 @@ sensor:
|
||||
- platform: homeassistant
|
||||
entity_id: sensor.hello_world
|
||||
id: ha_hello_world
|
||||
- platform: homeassistant
|
||||
entity_id: climate.living_room
|
||||
attribute: temperature
|
||||
id: ha_hello_world_temperature
|
||||
- platform: ble_rssi
|
||||
mac_address: AC:37:43:77:5F:4C
|
||||
name: 'BLE Google Home Mini RSSI value'
|
||||
@@ -246,6 +250,10 @@ binary_sensor:
|
||||
- platform: homeassistant
|
||||
entity_id: binary_sensor.hello_world
|
||||
id: ha_hello_world_binary
|
||||
- platform: homeassistant
|
||||
entity_id: binary_sensor.hello
|
||||
attribute: world
|
||||
id: ha_hello_world_binary_attribute
|
||||
- platform: ble_presence
|
||||
mac_address: AC:37:43:77:5F:4C
|
||||
name: 'ESP32 BLE Tracker Google Home Mini'
|
||||
@@ -355,6 +363,10 @@ text_sensor:
|
||||
- platform: homeassistant
|
||||
entity_id: sensor.hello_world2
|
||||
id: ha_hello_world2
|
||||
- platform: homeassistant
|
||||
entity_id: sensor.hello_world3
|
||||
id: ha_hello_world3
|
||||
attribute: some_attribute
|
||||
- platform: ble_scanner
|
||||
name: Scanner
|
||||
|
||||
|
Reference in New Issue
Block a user