Is this possible? Can I run a task forever without blocking my integration? Will hass.async_create_task do it?
The purpose is to be event driven, not poll based. My alternative would be calling update() every second.
Is this possible? Can I run a task forever without blocking my integration? Will hass.async_create_task do it?
The purpose is to be event driven, not poll based. My alternative would be calling update() every second.
For that, there is the binary_sensor template:
- binary_sensor:
name: something you like
state: "{{ trigger.json.part of the event that is giving the state }}"
device_class: some device class
trigger:
platform: event
event_type: some event you want to listen to
event_data:
device_id: highly recommended as the event could be fired from various devices
Then you can base your automation on the binary sensor, event driven.
More info around the middle of that page:
Right but I need it to run actual python code. I have a function in my integration but its going to be blocking without something that runs it in the background without blocking the rest.