Water pump with interval slider?

Hi,
I’m building a hydroponic (ebb&flood) system for chilis and would like to have adjustable interval for waterpump and in future maybe even override interval if my greenhouse gets too warm.

What would be best method to implement this?
I’ve been playing with:

  • id: waterpump
    alias: EBB Waterpump controller
    trigger:
    platform: time
    hours: 0
    #minutes: /input_number.slider1
    minutes: /30
    seconds: 0
    action:
    • service: switch.turn_on
      data:
      entity_id: switch.ebb_pump
    • delay: ‘00:00:59’
    • service: switch.turn_off
      data:
      entity_id: switch.ebb_pump

but I can’t figure out how to use slider in minutes?
HA says “ValueError: could not convert string to float: ‘input_number.slider1’” when I try to enable automation.

can you use the </> button around your yaml? Can’t see the format to provide feedback.

Also, as an FYI, you cannot use a template inside a trigger. You can only use hard code numbers. Thats why you are getting the valueError, its looking for a number and you are giving it a string.

If you want to have a variable trigger, you can do the following:

- alias: EBB Waterpump Controller
  trigger:
    platform: time
    minutes: /1
  condition:
    condition: template
    value_template:  {{ (now().hour*24*60+now().minute) % input_number.slider1 == 0 }}
  action:
    - service: switch.turn_on
      data:
        entity_id: switch.ebb_pump
    - delay: '00:00:59'
    - service: switch.turn_off
      data:
        entity_id: switch.ebb_pump

This will trigger every minute but only fire in increments of input_number.slider1. Your slider units are minutes, and the first trigger will always occur at midnight. The last trigger in the day and the first trigger in the day may not have the same separation as the first trigger to last trigger - 1.

This line of code is unique and may confuse you.

(now().hour*24*60+now().minute) % input_number.slider1

What this is called is ‘mod’. The percent sign is dividing the first number by the second number and returning the remainder. Example:

5 / 4 will return a remaining value of 1. 4 / 4 will return a remaining value of 0:

So, the equation will fire every increment of ‘mod’ when time mod slider = 0:

    value_template:  {{ (now().hour*24*60+now().minute) % input_number.slider1 == 0 }}

Thank you petro!
I think I got it working, but will keep testing configuration for few days before actually start using, I’ll get back to this if anything is wrong.

EDIT:
I had to tweak it a bit to get it working:
value_template: '{{ (now().hour*24*60+now().minute) % states.input_number.slider1.state | int == 0 }}'

but now it’s just turning pump ON and OFF in about 5 sec interval when automation is triggered.

- id: waterpump
  alias: EBB Waterpump controller
  trigger:
    platform: time
    minutes: /1
  condition:
    condition: template
    value_template:  '{{ (now().hour*24*60+now().minute) % states.input_number.slider1.state | int == 0 }}'
  action:
    - service: switch.turn_on
      data:
        entity_id: switch.ebb_pump
    - delay: '00:00:59'
    - service: switch.turn_off
      data:
        entity_id: switch.ebb_pump

Check your ha log and see when the event is being fired. Also, i’m not sure why you need to convert the slider value to an int, it should already be an int.

2018-04-02 21:30:29 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 2803056716: Sending {'id': 2, 'type': 'event', 'event': {'time_fired': datetime.datetime(2018, 4, 2, 18, 30, 29, 204984, tzinfo=<UTC>), 'event_type': 'state_changed', 'origin': 'LOCAL', 'data': {'old_state': <state automation.ebb_waterpump_controller=on; id=waterpump, friendly_name=EBB Waterpump controller, last_triggered=2018-04-02T21:30:28.218818+03:00 @ 2018-04-02T21:24:53.114969+03:00>, 'new_state': <state automation.ebb_waterpump_controller=on; id=waterpump, friendly_name=EBB Waterpump controller, last_triggered=2018-04-02T21:30:29.204891+03:00 @ 2018-04-02T21:24:53.114969+03:00>, 'entity_id': 'automation.ebb_waterpump_controller'}}}

Nothing else. It seems it fires trigger every second.

- id: waterpump
  alias: EBB Waterpump controller
  trigger:
    platform: time
    minutes: /1
  condition:
    condition: template
    value_template:  '{{ (now().hour*24*60+now().minute) % states.input_number.slider1.state | int == 0 }}'
  action:
    - service: switch.turn_on
      data:
        entity_id: switch.ebb_pump
    - delay: '00:00:59'
    - service: switch.turn_off
      data:
        entity_id: switch.ebb_pump

Without “| int”:

2018-04-02 21:45:00 INFO (MainThread) [homeassistant.core] Bus:Handling <Event system_log_event[L]: exception=Traceback (most recent call last):
  File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/automation/__init__.py", line 335, in async_trigger
    if skip_condition or self._cond_func(variables):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/automation/__init__.py", line 444, in if_action
    return all(check(hass, variables) for check in checks)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/automation/__init__.py", line 444, in <genexpr>
    return all(check(hass, variables) for check in checks)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/condition.py", line 317, in template_if
    return async_template(hass, value_template, variables)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/condition.py", line 299, in async_template
    value = value_template.async_render(variables)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py", line 132, in async_render
    return self._compiled.render(kwargs).strip()
  File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/srv/homeassistant/lib/python3.5/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
TypeError: unsupported operand type(s) for %: 'int' and 'str'

that’s weird. I’m probably remembering incorrectly.

Yeah, i’m not sure why that is.

Try this for your value template:

value_template: >
  {% set t = now().hour*24*60+now().minute | int %}
  {% set m = states.input_number.slider1.state | int %}
  {{ t%m == 0 }}

Without int value is 120.0.

Switch is a esp8266 via mqtt and works just fine even with automation without slider:

switch ebbpump:
  platform: mqtt
  name: 'EBB Pump'
  state_topic: 'state/ebb/pump'
  command_topic: 'state/ebb/pump'
  qos: 0
  payload_on: "ON"
  payload_off: "OFF"
  optimistic: false
  retain: true

Slider:

input_number:
  slider1:
    name: EBB Pump interval
    icon: mdi:timer
    initial: 120
    min: 15
    max: 480
    step: 15
    unit_of_measurement: min

I’ll try that, takes few minutes to trigger now.

Ah, looks like a float. That would be why. For some reason I thought sliders were ints, I must be remembering incorrectly.

As for the value_template change, I’m just making sure that we are forcing the correct types for mod. Mod requires int%int and I’m wondering if .minute is not an integer.

I had the same issue on my setup. Slider value showed up as 72.0 instead of what my thermostat code wanted (72). I did this in HA

payload: ‘{{states(“input_number.slider1”) | round|int }}’

Does not work neither, bouncing ON and OFF.
Automation itself works just fine though :smile:
Could this issue be in actions?

You think this could help to bouncing ON and OFF?

Honestly, I don’t know. But it would be easy to check. Just add the round function to your code.

Well, that didn’t help neither.

But now after automation has triggered and pump has went ON and OFF for a while, pump stays ON for a minute or so and then goes OFF:

This may not help, but let me post all my code for my slider/thermostat
Here is my code from input_number.yaml

   name: Temperature
   initial: 72
   min: 65
   max: 80
   step: 1

Here are 2 snippets from my automations file

trigger:
 platform: state
 entity_id: input_number.slider1
action:
 service: "mqtt.publish"
 data_template:
   topic: "topic/changetemp"
   #retain: "true"
   payload: '{{states("input_number.slider1") | round|int }}'

And

  trigger:
    platform: state
    entity_id: sensor.desired_temperature

  action:
    service: input_number.set_value
    data_template:
      entity_id: input_number.slider1
      value: '{{states("sensor.desired_temperature") | round|int  }}'

@ericleejoe
You send values directly to remote controller, right?
As You move slider, it sends a new value?
I’m quite a n00b here, so bare me out, please :slight_smile:

You don’t have any other automations with this water pump, do you?

@petro As far as I can tell, no. Only instances of switch.ebb_pump are in this automation.

try changing this line:

  trigger:
    platform: time
    minutes: /1

to:

  trigger:
    platform: time
    minutes: '/1'

Did not help.
Not with:

value_template:  '{{ (now().hour*24*60+now().minute) % states.input_number.slider1.state | round | int == 0 }}'

Or:

value_template: >
  {% set t = now().hour*24*60+now().minute | int %}
  {% set m = states.input_number.slider1.state | round | int %}
  {{ t%m == 0 }}

Now it does not stay on afterwards anymore :joy: