Options for scheduling an automation

Hello community,

I have been working with a recent project of a fish feeder for when I am on vacation.

Thus far, I have a servo configured with a slider that works.

I am checking to see what would be the best option for scheduling a feeding plan.

For example, every other day at 16:00, and have it advance the value ‘35’

This is what I have thus far: Basically, when I set to vacation mode, it initializes the feeder to the start position.

<config> 
# Fish_feeder
input_number:
  servo_control:
    initial: 0
    min: -95   
    max: 80
    step: 1
    mode: slider

<automation>
- id: '1668872670069'
  alias: Vacation
  description: ''
  trigger:
  - platform: state
    entity_id:
    - input_boolean.vacation_mode
    from: 'off'
    to: 'on'
  condition: []
  action:
  - service: esphome.fish_feeder_control_servo
    data:
      level: -95

Next, I want to see what are some ideas, as I dont know, that I dont know, of where to go next for what would be a best practice to either loop or preferably to schedule a date time, then increment the current level ‘+35’
I appreciate your time an input.

use a time trigger to trigger at 16:00 every day.

then as a condition check that the automation last triggered time was greater than 24 hours ago. I would probably add a couple of minutes to that just to be sure so use 24 hours and 5 minutes.

I don’t know how you control the servo motor so I can’t help you with that part.

do you just tell it to go to a value of 35 every time or does the system retain the current position and you need to tell it to go to “current position + 35”?

I will check this out, seems to be a good option if the automation would keep the current value of the servo. For setting the value, I would need to get the current setting, then add 35. If this was python, that would be easy, but this is all too new to me ;).
Regards,

If you are happier with python why not try pyscript for your automation?

I find that creating a special calendar in Google works well. Google has many options for calendar repeats. Just trigger the automation based on the event in the appropriate google calendar. That way you can easily change it from anywhere through google. So for example, you can delete one of a repetition because you don’t want it to run that time, or add in multiple events on the fly.

Many people will not like that this requires internet access though.

Here is a great example of you don’t know, what you don’t know. I can’t say that I am ‘happier’ with python, just more familiar. This will be in my ‘must check it out’ wheel house to see what is available. I have used micropython in the past, even though limited libraries was still very usable.

I haven’t tested it, but your automation in pyscript is going to look a little like this:

from datetime import datetime, date

state.persist('pyscript.vacation_last_run')

@state_trigger("input_boolean.vacation_mode == 'on' and input_boolean.vacation_mode.old == 'off'")
def vacation():
    input_number.servo_control.set_value(str(-95.0))

@time_trigger("once(16:00)")
@state_active("input_boolean.vacation_mode == 'on'")
def vacation_daily():
    last_run = datetime.strptime(pyscript.vacation_last_run, '%Y-%m-%d').date()
    if (date.today() - last_run).days > 1:
        new_value = int(input_number.servo_control) + 35
        input_number.servo_control.set_value(str(new_value))
        pyscript.vacation_last_run = date.today()

Why not use the schedule helper for that?

Thank you again, seems to be basically where I was heading. Additionally, I have been checking out a few of the different ways to interact with HA via pyscript

I had also added in a way to call a function for the servo to detach after it advanced. I had seen a few other posts related to it, and I found that if I did not have a task.sleep(2) before the detach call, if would not work, once the sleep was in, it was fine.

Regards

1 Like