is there a way to tigger a automation by a entity before the state of the entity is changed?
I think about a lamp which is turned off delayed or stepwise with an specific dim value. It’s clear to me to do this with an additional helper as a trigger source:
helper → automation → lampOutput
but is there a way to do without a helper, like this:
Hi Magnus,
thank you for your reply.
I don’t feel my question so cryptic. Anyhow I’ll try to put it straight to the point:
I’ve a ESPHome Light component. What I want to do now is that when I push the button to turn this light off, first dim it to 40% and then, delayed, turn it off after 30s.
I not want to use an additional helper switch for this because then I have to link every other inupt source (which is used to control the lamp) to the helper and not to the lamp.
Accomplishing this in a bombproof way with only an automation seems difficult/impossible to me. An automation can only be triggered by something that has already happened.
If the state updates quickly enough in Home Assistant, but the physical light itself is slow to react, you could potentially make an automation that immediately restores the previous state of the light, then proceeds with your dimming and delay. But odds are this would make the light flicker off and on in the process.
More foolproof would be to make an intermediary template light. That would only work for any commands that passes through HASS though, not if you have anything that controls this light through other platforms or devices which talk directly to the light.
An automation something like this would interrupt the light turning off and instead dim to 40%, but as already mentioned the light may unavoidably flicker off for a split second anyway. Not tested at all, probably has typos or something I’ve forgotten, etc.
maybe one further question to your statement regarding an intermediary light device. Is there an easy way to map the base functions between this intermediary device and the esp-home light? Must this also be done by autmations? E.g.: when I want to turn the eps-home light on with an dim ratio of 80%?
I haven’t used template lights myself to can only speak hypothetically. Within the light template itself you define what should happen on turn_on, turn_off etc. Unfortunately it looks like turn_on only receives brightness and transition and not any of the other attributes you can set from an automation using just a light.turn_on action, so you may need to add manual actions for any other attributes your actual light supports (set_temperature, set_rgb, etc.).
But since this is an ESPHome light, it may be possible to implement on the light itself? I would ask about it in the ESPHome section of this forum. I have zero experience with ESPHome unfortunately but considering getting the Sonoff fan controller and flash with ESPHome sooner or later.