项目作者: bulletmark

项目描述 :
Schedule Watts Clever Switches
高级语言: Python
项目地址: git://github.com/bulletmark/wcscheduler.git
创建时间: 2019-01-01T07:09:34Z
项目社区:https://github.com/bulletmark/wcscheduler

开源协议:

下载


WCSCHEDULER - Schedule Watts Clever Switches

This is a Raspberry Pi program to switch one or more Watts Clever RF
switches to turn mains powered devices on or off at specified times and
days of week. It uses my Python module
wcccontrol which controls
Watts Clever switches via an RF transmitter. It also runs a small
internal webserver to receive webhooks commands from the internet, e.g.
from IFTTT using Google Assistant (V2 since Sep
2022), to remotely switch the devices.

The latest version of this document and code is available at
https://github.com/bulletmark/wcscheduler.

Installation

Requires Python 3.6 or later. Does not work with Python 2.

  1. git clone https://github.com/bulletmark/wcscheduler.git
  2. cd wcscheduler
  3. python3 -m venv .venv
  4. .venv/bin/pip install -r requirements.txt

The above will install
wccontrol in your local .venv/
dir but you then need to follow the instructions to make the GPIO
accessible
and then to program the switches.

Be sure to set up the gpio group and udev rules etc as described and
also program the switch groups and addresses. Run .venv/bin/wccontrol
from within your wcscheduler dir to program the switches.

Configuration

Copy the sample
wcscheduler.conf
configuration file to ~/.config/wcscheduler.conf and then edit the
sample settings in that target file to your requirements. You can add
multiple on/off times for multiple devices as described by the comments in
that file.

  1. cp wcscheduler.conf ~/.config/
  2. vim ~/.config/wcscheduler.conf

Setting times based on Sunrise and/or Sunset

You can set absolute on and off times, or you can set times based on
sunrise and sunset events, with a +/-
delay, for a location. A location is specified as a latitude and
longitude pair of coordinates. See the instructions in the sample
configuration
file
.
Sunrise and Sunset times are fetched from the free Sunrise Sunset
API
.

systemd Configuration for Auto Start etc

Copy the included
wcscheduler.service
to /etc/systemd/systemd/ and edit the #TEMPLATE# values within that
target file:

  1. sudo cp wcscheduler.service /etc/systemd/systemd/
  2. sudoedit /etc/systemd/systemd/wcscheduler.service

Then:

  1. sudo systemctl enable wcscheduler
  2. sudo systemctl start wcscheduler

If you change the configuration then restart with:

  1. sudo systemctl restart wcscheduler

To see status and logs:

  1. systemctl status wcscheduler
  2. journalctl -u wcscheduler

IFTTT Webhook Configuration

You can set up an IFTTT webhook applet e.g. which
can be trigged by Google Assistant (V2) to switch your devices remotely by
voice command from your phone or from a Google home device. Configure a
IFTTT webhook POST JSON command with webhook and
action keys in the body as a minimum. You can also include the
created key which can be used to time contrain the message (see the
comments about webdelay in
wcscheduler.conf).
The webhook key must match the webhook name you configure in the
corresponding outputs section of your ~/.config/wcscheduler.conf.
E.g.:

  1. {
  2. "webhook": "webhook_name"
  3. "action": "{{SceneName}}",
  4. "created": "{{ActivatedAt}}",
  5. }

As required for Google Assistant V2 integration with IFTTT, if you want
to switch a light on and off then you will need 2 web hooks, one for
Google Assistant scene “Activate Lights On” and another for scene
“Activate Lights Off”. Both will be configured with the same JSON post
data and the SceneName will convey the desired action by containing
one of the words on, enable, set, true, or yes to activate the
function (any case), and not one of those words to de-activate the
function.

Be sure to specify webport in ~/.config/wcscheduler.conf for the
port for the web server to listen on and receive JSON POST messages. If
webport is not set, or there are no webhook values set for any
outputs, then the internal web server will not be started. A typical
home user will need to forward the port from their internet router to
the Raspberry Pi running this application.

Command Line Usage

Type wcscheduler -h to view the following usage summary:

  1. usage: wcscheduler [-h] [-c CONFIG] [-C]
  2. Program to schedule control of Watts Clever switches.
  3. options:
  4. -h, --help show this help message and exit
  5. -c CONFIG, --config CONFIG
  6. alternative configuration file
  7. -C, --no-cache do not use sunset/rise API cache

License

Copyright (C) 2019 Mark Blakeney. This program is distributed under the
terms of the GNU General Public License.
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or any later
version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License at https://www.gnu.org/licenses for more details.