Hi!
Is it possible to add custom attributes to an entity?
I’m trying to figure out a good way of managing extra information for each of my lights for my lighting control without using input_booleans or the template platform
/R
Hi!
Is it possible to add custom attributes to an entity?
I’m trying to figure out a good way of managing extra information for each of my lights for my lighting control without using input_booleans or the template platform
/R
HA will allow you to add custom attributes to an entity with the restful API.
Thanks!
So I should be able to augment existing entities in HASS using the Rest component?
I guess that any custom attributes needs to be re-created if I restart HASS
I will look delve into it.
/R
You can do this fairly easily with AppDaemon - some users have even created entirely new entities this way.
Yeah I’ve been thinking about testing the App Daemon. Though I still want to learn Home Assistant more in detail. Also its a small burden to need to keep additional systems up to date instead of having everything in HASS. (I know I complain)
Coming from OpenHab I feel the documentation a bit lacking so far which means a lot more of experimentation is necessary.
But I guess I will have to take the plunge sooner or later. Seems much easier to get clean and complex functions done the AppDaemon way over the Yaml way.
Sorry to dig up an old thread, but I can’t seem to find any information on this.
Do you have an example of how to create an entirely new entity within AppDaemon?
Just use the set_state()
call and a new entity will be created if one doesn’t exist.
This is BRILLIANT! Thank you!
A small issue with using set_state to create entities…
The entity is created and appears in the UI perfectly. However, when the entity is changed in the UI, the state does not change.
I see this fired on the event bus:
2017-02-01 16:12:05.000114 DEBUG {'service_call_id': '1977888976-7', 'service': 'select_option', 'domain': 'input_select', 'service_data': {'entity_id': 'input_select.test_livingroom_occupancy_select', 'option': 'On'}}
However, I can’t figure out what magic I need to send to listen_event() to handle it.
My code for creating it is simple:
self.set_state(self._occupancySelectEntityId, state = modes[0], attributes = {"options": modes, "hidden": False})
where self._occupancySelectEntityId = input_select.test_livingroom_occupancy_select and modes = [‘Auto’, ‘On’,‘Off’]
of course, AFTER I ask for help, I figure it out…
For anyone else looking for this… call listen event this way:
self.listen_event(self.select_change,'call_service', service = "select_option", domain = "input_select")
And then write your callback something like this:
def select_change(self, event_name, data, kwargs):
data = data["service_data"]
if data['entity_id'] == self._occupancySelectEntityId:
self.log('Select Change ' + data["option"])
self.set_state(self._occupancySelectEntityId, state = data["option"])
Note, you can’t use self.select_option() to set the state, because this actually fires the same event you just listened for, it doesn’t actually change the state.
For people stumbling on this topic. You can also define an attribute in the customization and then use that attribute in automation. Just tested this on HA 69.1. it looks like this:
> sensor.raspCpuload1:
> user_attr1: raspberrypi/cpuload1
and use of it looks like this:
> action:
> - service: mqtt.publish
> data_template:
> topic: "home/sensors/systems/{{ trigger.to_state.attributes.user_attr1 }}"
> payload: "{{ trigger.to_state.state }}"
> qos: 2
What is the exact API endpoint to do that? I am browsing https://developers.home-assistant.io/docs/en/external_api_rest.html back and forth and cannot find that feature.
EDIT: ah, maybe you mean the attributes of the state?
{
'state': 'ok',
'attributes': {
'hello': 'world'
}
}
I was hoping for the ability to add a custom name via the API.
Updates or creates the current state of an entity.
Yes, that one I know - I was looking for the ability to add a custom name via the API (see the edit of my question)