Power socket daily schedule - Schedy?

Hi all, Total noob to HA so apologies in advance. I’m running HA on Freenas and have been dabbling with yaml and starting to get somewhere but there is a schedule I want to develop that I can’t find a similar example of, which is surprising given how common a scenario it must be. It’s basically an HA equivalent of one of those digital timer power sockets that can be programmed for days of the week.

I am going to get a Zwave power socket that I want to use to control my coffee machine to come on and off at specific times on given days of the week. I want to have a Mon-Fri on and off time schedule, and then a Sat-Sun on and off schedule. I’d also like to be able to override this at any time with a simple virtual switch.

What’s the simplest method to achieve this?

Rather than coming begging as a new forum member, I’ve at least had a crack at it, using Schedy. The idea is that the schedule can change depending on whether I’m working from home or at the office, and there is a means to overide the schedule by switching it to off or on (constant). I have no idea if the below code is correct though (I adapted it from the Schedy tutorial) and I’ve realised I don’t really know how I integrate it with HA and link it to the switch entity. Can someone help me get it over the line please?

## This goes in schedy_coffee.yaml in AppDaemon’s apps directory:

schedy_coffee:  # This is our app instance name.
  module: hass_apps_loader
  class: SchedyApp

  actor_type: switch

  expression_environment: |
    def schedule_mode():
        return state("input_select.schedule_mode")

  watched_entities:
  - input_select.schedule_mode

  rooms:

    kitchen:
      actors:
        switch.kitchen_1:
      schedule:
      - v: "ON"
        rules:
        - weekdays: 1-5   #Mon-Fri
          rules:
          - rules:
            - x: "Next() if schedule_mode() == 'Normal' else Break()"
            - { start: "06:00", end: "08:00" }
          - rules:
            - x: "Next() if schedule_mode() == 'WFH or on leave' else Break()"
            - { start: "06:30", end: "15:00" }
          - rules:
            - x: "Next() if schedule_mode() == 'Off' else Break()"
            - v: "OFF"
          - rules:
            - x: "Next() if schedule_mode() == 'On (constant)' else Break()"
            - v: "ON"
        - weekdays: 6-7   #Sat-Sun
          rules:
          - rules          
            - x: "Next() if schedule_mode() =! 'Off' else Break()"          
            - { start: "06:30", end: "10:00" }
            - { start: "12:00", end: "15:00" }
          - rules
            - x: "Next() if schedule_mode() == 'On (constant)' else Break()"
            - v: "ON" 
          - v: "OFF"


## This goes in the HA configuration.yaml

input_select:
  schedule_mode:
    name: Coffee machine schedule mode
    options:
    - Normal
    - WFH or on leave
    - Off
    - On (constant)

I think it would be better to ask your question in the Schedy topic over here:

Hi @axg20202

Welcome to HA and Schedy!

To use Schedy, you’ll need to install it first :slight_smile:

Please see the Getting Started page to find the installation method that’s appropriate for you.

After that’s done, we can have a further look at your config, but it looks not bad at first glance, even though there’s room for simplification.

Best regards
Robert

Well, just one hint for simplifying the config:

These constant on/off sub-schedules aren’t really necessary. It would be much simpler if you add two rules right at the top of your schedule, independent of the weekday or any value, like so:

- x: "'on' if schedule_mode() == 'On (constant)' else Next()"
# ... and one for constant off

EDIT: You could then also remove the sub-schedule that checks for != 'OFF' at weekends.

Thanks all - very helpful.

One query I have is whether I need the v = “on” at the top of the schedule coding. This value was originally temperature (presumably the target temperature) for the Schedy tutorial based on a thermostart timer. So, in a simpler switch schedule like mine, do I need to specify this value state?

Values are inherited into sub-schedules, so since you don’t specify a value in the innermost rules, Schedy goes upwards until it finds one.

EDIT: I think the behavior you’re not certain about is described in the docs chapter about scheduling basics. Maybe re-read that.

Thanks. Quite right - RTFM! :grinning: I’ll check it out.

Ah, and while you’re at it, the development version of the docs has been restructured a little to make some things easier to understand.