Shelly relay schedule screen

Managing Shelly relay schedules remotely from Home Assistant

When I was first getting started with Home Assistant in 2018 or so, part of my job was assisting with the facilities management. The building relied heavily on Siemens APOGEE controllers for HVAC control, which controlled VSD fans, relays and actuators for hot/cold water circuits. Coming from a SysAdmin background, I was surprised to learn at the time that the programming of these was done on each controller, and the Building Management System (BMS) was just there to monitor and send commands to these controllers centrally.

While this seemed a little archaic to me at the time, I quickly saw the benefits to reliability – we didn’t have to worry about the HVAC shutting down when we needed to reboot the server, and when one of the controllers failed, it only impacted the immediately connected devices.

And so, one of my non-negotiable requirements for home automation is that the house should continue to function even if Home Assistant is down.

At home, I swapped Siemens Insight for Home Assistant, and the BACnet APOGEE controllers for Shelly relays. The Shellys have a basic weekly schedule built in which is fine, but the integration doesn’t currently expose the schedule to Home Assistant to be able to control this, or at least a way of disabling the schedule if you are on holiday for example.

Thankfully, the Shelly API Reference shows us there is a simple schedule flag which we can utilise. Using this knowledge, we can implement a RESTful Switch in Home Assistant to disable or enable the weekly schedule.

switch:
  - platform: rest
    name: "Towel Rail Remote Schedule"
    resource: http://192.168.1.201/settings/relay/0
    method: post
    body_on: "schedule=true"
    body_off: "schedule=false"
    is_on_template: "{{ value_json.schedule }}"

There is also a way of setting the schedule rules through the API too. This could be useful if you just want a different schedule rather than enabling or disabling it – but I haven’t had a requirement to set this up yet. If you do – please share your configuration 🙂


Posted

in

by

Comments

One response to “Managing Shelly relay schedules remotely from Home Assistant”

  1. Bruce Avatar
    Bruce

    Thanks James – this helped as a starting point to create a switch to turn the schedule on/off on my Shelly Plus 2PM. The code you posted works with the first gen relays. The Shelly Plus 2PM uses the gen2 API (https://shelly-api-docs.shelly.cloud/gen2/), which is different – a but more powerful, but slightly more complicated. For anyone else trying to do something similar, here is an equivalent bit of code that creates a switch to control the first schedule in a 2PM:

    switch:
    – platform: rest
    name: “Towel Rail Remote Schedule”
    resource: http://192.168.1.201/rpc
    method: post
    headers:
    Content-Type: application/json
    body_on: ‘{“id”:1,”method”:”Schedule.Update”,”params”:{“id”:1,”enable”:true}}’
    body_off: ‘{“id”:1,”method”:”Schedule.Update”,”params”:{“id”:1,”enable”:false}}’
    state_resource: http://192.168.1.201/rpc/Schedule.List
    is_on_template: “{{ value_json[‘jobs’][0][‘enable’] }}”

Leave a Reply