danobot / entity-controller

Home Assistant Entity and lighting controller for managing devices with timers, scripts, and sun-based time restrictions.
https://danobot.github.io/ec-docs/
GNU General Public License v3.0
294 stars 40 forks source link

External event as a sensor on event #333

Open rzulian opened 2 months ago

rzulian commented 2 months ago

Description

I need that I can fire an event from automations that can act as a sensor. The EC has its own sensors (duration and time reset) and it's time constrained. I've tried to use activate

  - service: entity_controller.activate
    data:
      entity_id: entity_controller.my_ec

, but it's rising an error if the EC is constrained.

So I've modified the function in theentity_services.py to this

def async_entity_service_activate(self):
    """ Activates the entity controller"""

    if(self.model is None):
        return

    def async_entity_service_activate(self):
    """ Activates the entity controller"""

    if(self.model is None):
        return
    if self.model.is_idle() or self.model.is_active_timer() or self.model.is_blocked():
        self.model.log.debug("Activating the Entity Controller")
        self.model.set_context()
        self.model.update(last_triggered_by="external_event")
        self.model.sensor_on()

    # self.model.activate()

And it looks it's working just fine. Do you think that this can be the right way? I might add an async_entity_service_sensor_on just for that.

Tabisch commented 4 days ago

it's rising an error if the EC is constrained

This looks like expected behavior You can either go to idle or overridden The is a flow chart for all the states here https://danobot.github.io/ec-docs/images/state_diagram.png

I need that I can fire an event from automations that can act as a sensor.

Maybe a helper switch works for you. I think you can turn those on and off from an automation. EC should work just fine with those