Use automation conditions result in action


I’m currently working on my first automation so sorry if this is a noob question.

Basically I have this hydroponics “garden” in my living room. It has a lamp and I want to guarantee my garden ~9 hours of light per day without using unnecessary electricity.

My idea is to, every 15 minutes between 9 AM and 6 PM, check if there’s enough sun for the lamp to be turned off (after sunrise/before sunset and cloudiness less than 15%). I’ve set up the automation that turns on the lamp:

  - alias: 'Hydroponics - Turn On'
      - platform: time
        minutes: '/15'
        seconds: 00
        condition: and
          - condition: time
            after: '9:00:00'
            before: '18:00:00'
          - condition: or
              - condition: numeric_state
                entity_id: sensor.weather_cloudiness
                above: 15
              - condition: sun
                after: sunset
              - condition: sun
                before: sunrise
        service: switch.turn_on
        entity_id: switch.hydroponic_switch

I was about to set up the automation to turn off the lamp (that basically negates everything) but was wondering if there’s a smarter/easier way to do this other than basically duplicating everything. E.g. if I want to tweak cloudiness to 20%, I’ll have to remember to do it in both places which doesn’t feel optimal.

Is there a way to use the result of the conditions in the action?
E.g. if the conditions result to false, turn off the lamp?

Or any other way to handle this better?

Hi @Adabelle_Leiram,

As far as I know you can’t have that level of info, other than maybe with some more advanced scripting with appdeamon.

A fix for the issue of not having to edit a value multiple times could be to have a “input_number” where you slide the level of cloudiness that should be in the conditions and then just use the state of the input_number in all automations you want.

Edit: And you can of course also use the state of the input_number as a trigger for turning of the lamp. It might seems a little over complicated at first but it often is a good practise to have some kind of intermediary “dummy-input” that gets activated by a device or change by the user and then read by automations. That way you can easily make changes in hardware or test stuff out. I have a input_select with all the possible states of me, home, not home, sleeping etc. I then use that as a kind of “hub” for my apartment, some devices changes it (and at certain times) others read the status and changes accordingly.

Hope this helps, sounds interesting with the hydroponics system :slight_smile:

1 Like

Thanks for all the advice. I think that as soon as I start playing around with tabs/groups etc I’ll look at a “dummy input” setup like you suggested. Would be tedious to have to keep updating the yaml file and reloading it just to change a small value.

I’m not so worried about more advanced scripting since I work with programming. Will check out appdaemon.

Thanks again for the tips!

PS: Hydroponics is awesome, it’s really fun to be able to grow your own food even if you live in a city apartment. Tastes much better and lasts much longer as well!

Create a template binary sensor, that indicates whether the lamp should be on or off, then you can use that in your on/off automations:

  - platform: template
        friendly_name: "Hydroponics on"
        entity_id: sun.sun
        value_template: >-
          {{ ( (now().hour >= 9) and (now().hour < 18) ) and (states.sun.sun.attributes.elevation|float < 0) or (states('sensor.weather_cloudiness')|float > 15) }}

It does the same as your conditions, from ‘09:00’ to ‘18:00’ (well, ‘17:59:59’) if the sun is below the horizon (elevation below zero) or cloudy is more than 15. Then your automation becomes:

  - alias: 'Hydroponics - Turn On'
      - platform: state
        entity_id: binary_sensor.hydroponics
        to: 'on'
        service: switch.turn_on
        entity_id: switch.hydroponic_switch


  - alias: 'Hydroponics - Turn Of'
      - platform: state
        entity_id: binary_sensor.hydroponics
        to: 'off'
        service: switch.turn_off
        entity_id: switch.hydroponic_switch

Thanks, this looks like a really smart solution! I’ll definitely give this a try!

Would it not be action: where you have condition: ? (I’m still getting my head around templates)

Haha probably a typo :slight_smile:

Yes, it’s a typo - I’ll fix that :slight_smile:

@Adabelle_Leiram - curious to learn about your hydroponics setup.

Did you build it yourself or is it an off-the-shelf solution?

Hi! I just bought IKEA’s kit :slight_smile:

1 Like