Automotation for Greenhouse?

So I’m working on automating the watering of my greenhouse and I’m using ESPEasy on a nodemcu dev board connected to mosquitto. I’ve managed to add 4 buttons configured like this:
switch:

  • platform: mqtt
    name: “Waterbed 1”
    state_topic: “/greenhouse/water_1/switch”
    command_topic: “/greenhouse/gpio/0”
    payload_on: “0”
    payload_off: “1”
    optimistic: true
    qos: 0

Could anyone point me in the right direction how to auomate HASS to run water_1 for 20 minutes, then water_2 for 20 minutes etc. every second day?

Here is how I would proceed, (not saying that it is the best solution or the most elegent one, tough)

First of all, I would defined an input boolean to decide if you should water that day or not (when you water your plants, that boolean is set ‘off’ for instance)

I would use a script for the watering process, like that

waterplants:
  alias: 'Water plants'
  sequence:
    - alias: 'Bed 1 ON'
      service: switch.turn_on
      entity_id: waterbed_1
    - delay:
        minutes: 20
    - alias: 'Bed 1 OFF"
      service: switch.turn_off
      entity_id: waterbed_1
    - alias: 'Bed 2 ON'
      service: switch.turn_on
      entity_id: waterbed_2
    - delay:
        minutes: 20
    - alias: 'Bed 2 OFF"
      service: switch.turn_on
      entity_id: waterbed_2
    - alias: 'Input bool to off"
      service: sate.turn_off
      entity_id:yourinputbool

and an automation to trigger the script

- alias: 'Time to water beds'
  trigger:
    - platform: time
      at: '19:00
  condition:
    - condition: state
      entity_id: yourinputboolean
      state: 'off'
      for:
        hours: 47
  action:
    - service: input_boolean.turn_on
      entity_id: yourboolean
    - service : script.turn_on 
      entity_id: script.waterplants

That’s one solution that should work without too much trouble (note that there is almost certainly mistakes in the code hereabove, do not try to simply copy/paste). There is probably a most elegent one, using appdeamon or something, but I am not used to this add-on.

as you are using a node mcu in your greenhouse, you may also use a humidity sensor (xiaomi flora sensor?) for plant beds, and water your plants exactly when the need it. It should be rather easy, cheap and make you lower the water consumption

2 Likes

Sweet thanks for the input. I’ve added it now with some modifications like this:

water_greenhouse:
  sequence:
    - alias: 'Bed 1 ON'
      service: switch.turn_on
      entity_id: switch.waterbed_1
      delay: '00:20:00'
    - alias: 'Bed 1 OFF'
      service: switch.turn_off
      entity_id: switch.waterbed_1
    - alias: 'Bed 2 ON'
      service: switch.turn_on
      entity_id: switch.waterbed_2
      delay: '00:20:00'
    - alias: 'Bed 2 OFF'
      service: switch.turn_off
      entity_id: switch.waterbed_2
    - alias: 'Bed 3 ON'
      service: switch.turn_on
      entity_id: switch.waterbed_3
      delay: '00:20:00'
    - alias: 'Bed 3 OFF'
      service: switch.turn_off
      entity_id: switch.waterbed_3
    - alias: 'Bed 4 ON'
      service: switch.turn_on
      entity_id: switch.waterbed_4
      delay: '00:20:00'
    - alias: 'Bed 4 OFF'
      service: switch.turn_off
      entity_id: switch.waterbed_4
    - alias: 'Input bool to off'
      service: state.turn_off
      entity_id: yourinputbool

But I keep getting

2017-06-05 11:00:27 ERROR (MainThread) [homeassistant.config] Invalid config for [script]: [delay] is an invalid option for [script]. Check: script->script->water_greenhouse->sequence->0->delay. (See /home/hass/.homeassistant/configuration.yaml, line 112). Please check the docs at https://home-assistant.io/components/script/
2017-06-05 11:00:27 ERROR (MainThread) [homeassistant.setup] Setup failed for script: Invalid config.
```
Thanks for the tip about xiaomi flora to, have been thinking about that but what I understand they degrade pretty fast so I'm holding off on that for a while!

Put a dash before all your delays:

water_greenhouse:
  sequence:
    - alias: 'Bed 1 ON'
      service: switch.turn_on
      entity_id: switch.waterbed_1
    - delay: '00:20:00'
    - alias: 'Bed 1 OFF'
      service: switch.turn_off
      entity_id: switch.waterbed_1
    - alias: 'Bed 2 ON'
      service: switch.turn_on
      entity_id: switch.waterbed_2
    - delay: '00:20:00'
2 Likes

Sweet, thanks @Bob_NL now I just have one last error:

2017-06-05 13:28:12 ERROR (MainThread) [homeassistant.config] Invalid config for [script]: Entity ID yourinputbool is an invalid entity id for dictionary value @ data['script']['water_greenhouse']['sequence'][12]['entity_id']. Got 'yourinputbool'. (See /home/hass/.homeassistant/configuration.yaml, line 112). Please check the docs at https://home-assistant.io/components/script/
2017-06-05 13:28:12 ERROR (MainThread) [homeassistant.setup] Setup failed for script: Invalid config.

should I change “yourinoutbool” to water_greenhouse as I declared it at the start instead? I’m not sure what @lambtho ment with that part :smiley: but this is my first script!

You have to define an input boolean first to be able to use it in your script.
The most logical will be to name it water_greenhouse indeed. In that case, implement like this:

input_boolean:
  water_greenhouse:
    name: Watering Greenhouse
    initial: on

change this:

    - alias: 'Input bool to off'
      service: state.turn_off
      entity_id: input_boolean.water_greenhouse

If you use this, the script will be switched off at the end of the sequence. Remember that you’ll have to define a seperate automation which enables the script again in 2 days.

1 Like

Thanks Bob, so completed it should look like this:

  input_boolean:
    water_greenhouse:
    name: Watering Greenhouse
    initial: on
  sequence:
    - alias: 'Bed 1 ON'
      service: switch.turn_on
      entity_id: switch.waterbed_1
    - delay: '00:20:00'
    - alias: 'Bed 1 OFF'
      service: switch.turn_off
      entity_id: switch.waterbed_1
    - alias: 'Bed 2 ON'
      service: switch.turn_on
      entity_id: switch.waterbed_2
    - delay: '00:20:00'
    - alias: 'Bed 2 OFF'
      service: switch.turn_off
      entity_id: switch.waterbed_2
    - alias: 'Bed 3 ON'
      service: switch.turn_on
      entity_id: switch.waterbed_3
    - delay: '00:20:00'
    - alias: 'Bed 3 OFF'
      service: switch.turn_off
      entity_id: switch.waterbed_3
    - alias: 'Bed 4 ON'
      service: switch.turn_on
      entity_id: switch.waterbed_4
    - delay: '00:20:00'
    - alias: 'Bed 4 OFF'
      service: switch.turn_off
      entity_id: switch.waterbed_4
    - alias: 'Input bool to off'
      service: state.turn_off
      entity_id: input.boolean.water_greenhouse

I’ve already made an automotation from the first suggestion that looks like this now when I’ve changed the boolean name:

- id: water_greenhouse
  alias: 'Time to water beds'
  trigger:
    - platform: time
      at: '19:00'
  condition:
    - condition: state
      entity_id: water_greenhouse
      state: 'off'
      for:
        hours: 47
  action:
    - service: input_boolean.turn_on
      entity_id: water_greenhouse
    - service : script.turn_on
      entity_id: script.watering

You’re almost there.

But I see you combined the input boolean and the script, that doesn’t work.
Use the script like you did before and configure the input boolean seperate. Like this:

Input boolean:

input_boolean:
  water_greenhouse:
    name: Watering Greenhouse
    initial: off

Script:

script:
  water_greenhouse:
    sequence:
     - alias: 'Bed 1 ON'
       service: switch.turn_on
       entity_id: switch.waterbed_1
     - delay: '00:20:00'
     - alias: 'Bed 1 OFF'
       service: switch.turn_off
       entity_id: switch.waterbed_1
     - alias: 'Bed 2 ON'
       service: switch.turn_on
       entity_id: switch.waterbed_2
     - delay: '00:20:00'
     - alias: 'Bed 2 OFF'
       service: switch.turn_off
       entity_id: switch.waterbed_2
     - alias: 'Bed 3 ON'
       service: switch.turn_on
       entity_id: switch.waterbed_3
     - delay: '00:20:00'
     - alias: 'Bed 3 OFF'
       service: switch.turn_off
       entity_id: switch.waterbed_3
     - alias: 'Bed 4 ON'
       service: switch.turn_on
       entity_id: switch.waterbed_4
     - delay: '00:20:00'
     - alias: 'Bed 4 OFF'
       service: switch.turn_off
       entity_id: switch.waterbed_4
     - alias: 'Input bool to off'
       service: state.turn_off
       entity_id: input.boolean.water_greenhouse

Thanks for having patience witht me, I’m starting to feel really dumb by now… think it’s time to go out and manually water the greenhouse :smiley:

I changed my script to look exactly like yours and added the following to configuration.yaml as the guide here said https://home-assistant.io/components/input_boolean/

input_boolean:
  water_greenhouse:
    name: Watering Greenhouse
    initial: on
    icon: mdi:water-pump

but then I get a new error message:

2017-06-05 13:58:11 ERROR (MainThread) [homeassistant.config] Invalid config for [script]: Entity ID input.boolean.water_greenhouse is an invalid entity id for dictionary value @ data['script']['water_greenhouse']['sequence'][12]['entity_id']. Got 'input.boolean.water_greenhouse'. (See /home/hass/.homeassistant/configuration.yaml, line 112). Please check the docs at https://home-assistant.io/components/script/
2017-06-05 13:58:11 ERROR (MainThread) [homeassistant.setup] Setup failed for script: Invalid config.

Looking at the error message I can’t see any difference in what it gets from the script and what I’ve used in the configuration.yaml file?

1 Like

I see what I did wrong, must be:

entity_id: input_boolean.water_greenhouse

No problem mate, we all have to learn :slight_smile:

1 Like

Woho, now the script isnt throwing me any more errors but I’m still getting some from the automation:

2017-06-05 15:33:40 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: Entity ID water_greenhouse is an invalid entity id for dictionary value @ data['action'][0]['entity_id']. Got None. (See /home/hass/.homeassistant/configuration.yaml, line 110). Please check the docs at https://home-assistant.io/components/automation/

I’ve tried reading up in https://home-assistant.io/docs/automation/trigger/ and https://home-assistant.io/components/input_boolean/ but still can’t see what I’ve missed…

##Water the greenhouse every 48hrs at 1900
- id: water_greenhouse
  alias: 'Time to water beds'
  trigger:
    - platform: time
      at: '19:00'
  condition:
    - condition: state
      entity_id: input_boolean.water_greenhouse
      state: 'off'
      for:
        hours: 47
  action:
    - service: input_boolean.turn_on
      entity_id: water_greenhouse
    - service : script.turn_on
      entity_id: script.water_greenhouse

And about learning, what’s the best resource/way to learn how to do all this correctly, want to learn so I can give something back!

So this is massively off topic but you might want to consider a self watering solution such as http://www.greenhousesensation.co.uk/chilligrow.html.

I added a water sensor to the tank that feeds the self watering plants, and it is very effective. I’m happy to provide more information on my project if you are interested, but I realise it’s a totally different direction for you :slight_smile:

The last five lines should be:

action:
    - service: input_boolean.turn_on
      entity_id: input_boolean.water_greenhouse
    - service : script.turn_on
      entity_id: script.water_greenhouse

The entity id is input_boolean.water_greenhouse not water_greenhouse

1 Like

@Naesstrom sorry for having provided an incomplete solution in my first post. I tought you were kinda familiar with automations and HASS,… if I knew that it was your first automation I would have paid more attention and make sure that it was a working solution first…

Hope you finally make it work with the help of the others…

@Naesstrom, what he says :grin:

For me, the best way was trial and error! And be very active on the community in both reading and discussing. There isn’t a all-in-1 tutorial or something like that, it just doesn’t work that way in my opinion.

1 Like

There is also a lot of full configuration examples on the website. I learnt a lot by reading those

1 Like

YES! Thanks everyone for helping me through it! No errors and it shows up with the automations now! :smiley:
I’ve tried reading the examples first and got some automations working before but never dared to venture into scripts! :blush:

One last thing, can I make a switch that calls the script somehow if I manually want to start the watering?

Finishing up the last of the wiring and making sure the connections are tight, then I’ll take some photos and write up something on how it’s working!

3 Likes

If you put the script on a card using groups, it will appear with a toggle switch. Toggling right activates the script.

Then, if you want it as a button, in customize put:

script.water_greenhouse:
  can_cancel: false 

And the toggle will be replaced with a ‘button’ saying Activate. Pressing Activate will manually run the script. Beware though that if you want to cancel the script halfway through the toggle might be better, otherwise you will have to manually call the stop script command to cancel midway through. Depends on your use case.

1 Like