Custom component - fire services

Hi there, I am trying to create a custom component, and I would like to change the state of an existing entity on homeassistant.

How do a call a service homeassistant.turn_on for an entity?

Assuming that you want to call this service from an async method:

await self._hass.services.async_call('homeassistant', 
                                     SERVICE_TURN_ON,
                                     {ATTR_ENTITY_ID: my_entity_id})

Otherwise:

self._hass.services.call('homeassistant', 
                         SERVICE_TURN_ON,
                         {ATTR_ENTITY_ID: my_entity_id})

Thank you. The second one worked for me.

1 Like