Last active 1716829951

Sample Platypush configuration file

config.yaml Raw
1################################################################################
2# Sample Platypush configuration file.
3#
4# Edit it and:
5# - Copy it to /etc/platypush/config.yaml for system installation.
6# - Copy it to ~/.config/platypush/config.yaml for user installation.
7# - Start the application with `-c <path-to-this-file>`.
8#
9# Since the configuration file also includes the custom integrations, you can
10# create a Platypush custom installation, with all the extra dependencies
11# required by the configured integrations, using the `platydock` or `platyvenv`
12# commands and passing this file as an argument. These commands will build a
13# Docker image or a Python virtual environment respectively, with all the
14# required extra dependencies inferred from your configuration file.
15#
16# A `scripts` directory with an empty `__init__.py` script will also be created
17# under the same directory as the configuration file. This directory can be
18# used to add custom scripts containing procedures, hooks and crons if you want
19# a full Python interface to define your logic rather than a YAML file.
20#
21# Please refer to the `scripts` directory provided under this file's directory
22# for some examples that use the Python API.
23################################################################################
24
25### ------------------
26### Include directives
27### ------------------
28
29###
30# # You can split your configuration over multiple files and use the include
31# # directive to import other files into your configuration.
32#
33# # Files referenced via relative paths will be searched in the directory of
34# # the configuration file that references them. Symbolic links are also
35# # supported.
36#
37# include:
38# - logging.yaml
39# - media.yaml
40# - sensors.yaml
41###
42
43### -----------------
44### Working directory
45### -----------------
46
47###
48# # Working directory of the application. This is where the main database will be
49# # stored by default (if the default SQLite configuration is used), and it's
50# # where the integrations will store their state.
51#
52# # Note that the working directory can also be specified at runtime using the
53# # -w/--workdir option.
54# #
55# # If not specified, then one of the following will be used:
56# #
57# # - $XDG_DATA_HOME/platypush if the XDG_DATA_HOME environment variable is set.
58# # - /var/lib/platypush if the user is root.
59# # - $HOME/.local/share/platypush otherwise.
60#
61# workdir: ~/.local/share/platypush
62###
63
64### -----------------
65### Cache directory
66### -----------------
67
68###
69# # Note that the cache directory can also be specified at runtime using the
70# # --cachedir option.
71# #
72# # If not specified, then one of the following will be used:
73# #
74# # - $XDG_CACHE_DIR/platypush if the XDG_CACHE_DIR environment variable is set.
75# # - /var/cache/platypush if the user is root.
76# # - $HOME/.cache/platypush otherwise.
77#
78# cachedir: ~/.cache/platypush
79###
80
81### ----------------------
82### Database configuration
83### ----------------------
84
85###
86# # By default Platypush will use a SQLite database named `main.db` under the
87# # `workdir`. You can specify any other engine string here - the application has
88# # been tested against SQLite, Postgres and MariaDB/MySQL >= 8.
89# #
90# # You can also specify a custom database engine at runtime (SQLAlchemy syntax
91# # supported) through the `--db` argument otherwise.
92# #
93# # NOTE: If you want to use a DBMS other than SQLite, then you will also need to
94# # ensure that a compatible Python driver is installed on the system where
95# # Platypush is running. For example, Postgres will require the Python pg8000,
96# # psycopg or another compatible driver.
97#
98# main.db:
99# engine: sqlite:////home/user/.local/share/platypush/main.db
100# # OR, if you want to use e.g. Postgres with the pg8000 driver:
101# engine: postgresql+pg8000://dbuser:dbpass@dbhost/dbname
102#
103# # NOTE: The short syntax `main.db: <engine_string>` is also supported.
104###
105
106### ---------------------
107### Logging configuration
108### ---------------------
109
110###
111# # Platypush logs on stdout by default. You can use the logging section to
112# # specify an alternative file or change the logging level.
113#
114# # Note that a custom logging directory can also be specified at runtime using
115# # the -l/--logsdir option.
116#
117# logging:
118# filename: ~/.local/log/platypush/platypush.log
119# level: INFO
120###
121
122### -----------------------
123### device_id configuration
124### -----------------------
125
126###
127# # The device_id is used by many components of Platypush and it should uniquely
128# # identify a device in your network. If nothing is specified then the hostname
129# # will be used.
130#
131# # Note that a custom device ID can also be specified at runtime using the
132# # -d/--device-id option.
133#
134# device_id: my_device
135###
136
137### -------------------
138### Redis configuration
139### -------------------
140
141###
142# # Platypush needs a Redis instance for inter-process communication.
143# #
144# # By default, the application will try and connect to a Redis server listening
145# # on localhost:6379.
146# #
147# # Platypush can also start the service on the fly if instructed to do so
148# # through the `--start-redis` option. You can also specify a custom port
149# # through the `--redis-port` option.
150# #
151# # If you are running Platypush in a Docker image built through Platydock, then
152# # `--start-redis` is the default behaviour and you won't need any extra
153# # documentation here.
154#
155# redis:
156# host: localhost
157# port: 6379
158# username: user
159# password: secret
160###
161
162### ------------------------
163### Web server configuration
164### ------------------------
165
166###
167# Platypush comes with a versatile Web server that is used to:
168#
169# - Serve the main UI and the UIs for the plugins that provide one.
170# - Serve custom user-configured dashboards.
171# - Expose the `/execute` RPC endpoint to send synchronous requests.
172# - Expose the `/ws/events` and `/ws/requests` Websocket paths, which can be
173# respectively by other clients to subscribe to the application's events or
174# send asynchronous requests.
175# - Stream media files provided by other plugins, as well as camera and audio
176# feeds.
177# - Serve custom directories of static files that can be accessed by other
178# clients.
179# - Provide a versatile API for hooks - the user can easily create custom HTTP
180# hooks by creating a hook with their custom logic that reacts when a
181# `platypush.message.event.http.hook.WebhookEvent` is received. The `hook`
182# parameter of the event specifies which URL will be served by the hook.
183#
184# The Web server is enabled by default, but you can disable it simply by
185# commenting/removing the `backend.http` section. The default listen port is
186# 8008.
187#
188# After starting the application, you can access the UI at
189# http://localhost:8008, set up your username and password, and also create an
190# access or session token from the configuration panel.
191#
192# This token can be used to authenticate calls to the available APIs.
193# For example, to turn on the lights using the /execute endpoint:
194#
195# curl -XPOST -H "Authorization: Bearer $TOKEN" \
196# -H "Content-Type: application/json" \
197# -d '
198# {
199# "type": "request",
200# "action": "light.hue.on",
201# "args": {
202# "lights": ["Bedroom"]
203# }
204# }' http://localhost:8008/execute
205#
206# If you want to serve the Web server behind a reverse proxy, you can copy the
207# reference configuration available at
208# https://git.platypush.tech/platypush/platypush/src/branch/master/examples/nginx/nginx.sample.conf
209
210backend.http:
211 # # Bind address (default: 0.0.0.0)
212 # bind_address: 0.0.0.0
213 # # Listen port (default: 8008)
214 port: 8008
215
216 # # resource_dirs can be used to specify directories on the host system that
217 # # you want to expose through the Web server. For example, you may want to
218 # # expose directories that contain photos or images if you want to make a
219 # # carousel dashboard, or a directory containing some files that you want to
220 # # share with someone (or other systems) using a simple Web server.
221 # #
222 # # In the following example, we're exposing a directory with photos on an
223 # # external hard drive other the `/photos` URL. An image like e.g.
224 # # `/mnt/hd/photos/IMG_1234.jpg` will be served over e.g.
225 # # `http://localhost:8008/photos/IMG_1234.jpg` in this case.
226 # resource_dirs:
227 # photos: /mnt/hd/photos
228
229 # # Number of WSGI workers. Default: (#cpus * 2) + 1
230 # num_workers: 4
231
232### -----------------------------
233### Plugin configuration examples
234### -----------------------------
235
236###
237# # The configuration of a plugin matches one-to-one the parameters required by
238# # its constructor.
239# #
240# # Plugin classes are documented at https://docs.platypush.tech/en/latest/plugins.html
241# #
242# # For example, there is a `light.hue` plugin
243# # (https://docs.platypush.tech/platypush/plugins/light.hue.html) whose
244# # constructor takes the following parameters: `bridge`, `lights` (default
245# # target lights for the commands), `groups` (default target groups for the
246# # commands) and `poll_interval` (how often the plugin should poll for updates).
247# #
248# # This means that the `light.hue` plugin can be configured here as:
249#
250# light.hue:
251# # IP address or hostname of the Hue bridge
252# # NOTE: The first run will require you to register the application with
253# # your bridge - that's usually done by pressing a physical button on your
254# # bridge while the application is pairing.
255# bridge: 192.168.1.3
256# # Groups that will be handled by default if nothing is specified on the request
257# groups:
258# - Living Room
259#
260# # How often we should poll for updates (default: 20 seconds)
261# poll_interval: 20
262###
263
264###
265# # Example configuration of the MQTT plugin.
266# # This plugin allows you to subscribe to MQTT topics and trigger `platypush.message.event.mqtt.MQTTMessageEvent`
267# # events that you can hook on when new messages are received.
268# # You can also publish messages to MQTT topics through the `mqtt.publish` action.
269#
270# mqtt:
271# # Host and port of the MQTT broker
272# host: my-mqtt-broker
273# port: 1883
274# # Topic to subscribe to. Messages received on these topics will trigger `MQTTMessageEvent` events.
275# topics:
276# - platypush/sensors
277#
278# # Extra listeners. You can use them to subscribe to multiple brokers at the same time.
279# listeners:
280# - host: another-mqtt-broker
281# port: 1883
282# username: user
283# password: secret
284# topics:
285# - platypush/tests
286###
287
288###
289# # Example configuration of a voice assistant.
290# # Several voice assistant plugins and engines are available - Google
291# # Assistant, Alexa, DeepSpeech, Picovoice etc.
292# #
293# # The Google Assistant is probably the most straightforward to configure and
294# # the richest in terms of features provided out-of-the-box and speech
295# # detection quality, while others may require further tinkering, may perform
296# # worse than the Google model, and/or may run models on-device which could not
297# # be within reach for some machines.
298# #
299# # Check the documentation of the `assistant.google` plugin for instructions on
300# # how to get a credentials file that you can use with a custom assistant
301# # installation.
302# #
303# # Note however that the Google Assistant plugin leverages the
304# # `google-assistant-library`, which has been deprecated a while ago by Google
305# # and it's unlikely to receive updates (although it still works and I'd still
306# # expect it to work).
307#
308# assistant.google:
309# # Path to your credentials file (by default it will look either under
310# # ~/.config/google-oauthlib-tool/credentials.json or
311# # <WORKDIR>/credentials/google/assistant.json
312# # credentials_file: ~/credentials/assistant.json
313# # If specified, then this sound will be played when a conversation starts
314# # conversation_start_sound: ~/sounds/assistant-start.mp3
315###
316
317###
318# # Example configuration of music.mpd plugin, a plugin to interact with MPD and
319# # Mopidy music server instances. See
320# # https://docs.platypush.tech/en/latest/platypush/plugins/music.mpd.html
321# # You can easily install the dependencies through pip install 'platypush[mpd]'
322#
323# music.mpd:
324# host: localhost
325# port: 6600
326###
327
328###
329# # Example last.fm scrobbler configuration, to synchronize your music
330# # activities to your Last.fm profile. You'll need to register an application
331# # with your account at https://www.last.fm/api.
332#
333# lastfm:
334# api_key: <API_KEY>
335# api_secret: <API_SECRET>
336# username: <USERNAME>
337# password: <PASSWORD>
338###
339
340###
341# # Plugins with empty configuration can also be explicitly enabled by specifying
342# # `enabled: true` or `disabled: false`. An integration with no items will be
343# # enabled with no configuration.
344#
345# clipboard:
346###
347
348###
349# # Enable the system plugin if you want your device to periodically report
350# # system statistics (CPU load, disk usage, memory usage etc.)
351# #
352# # When new data is gathered, an `EntityUpdateEvent` with `plugin='system'` will
353# # be triggered with the new data, and you can subscribe a hook to these events
354# # to run your custom logic.
355#
356# system:
357# # How often we should poll for new data
358# poll_interval: 60
359###
360
361###
362# # Example configuration for the calendar plugin. In this case, we have
363# # registered a Google calendar that uses the `google.calendar` integration, and
364# # a Facebook plugin and a NextCloud (WebDAV) plugin exposed over iCal format.
365# # Installing the dependencies: pip install 'platypush[ical,google]'
366# calendar:
367# calendars:
368# - type: google.calendar
369# - type: calendar.ical
370# url: https://www.facebook.com/events/ical/upcoming/?uid=your_user_id&key=your_key
371# - type: calendar.ical
372# url: https://my.nextcloud.org/remote.php/dav/public-calendars/id?export
373###
374
375###
376# # Example configuration for the alarm plugin. It is possible to define alarms
377# # both statically, i.e. through configuration snippets under the `alarm`
378# # section, and dynamically, i.e. with an `alarm.add` request with the
379# # configuration of the desired alarm.
380#
381# alarm:
382# # Media plugin that will be used to play the alarm audio.
383# # If not specified, the first available configured media plugin
384# # will be used.
385# media_plugin: media.vlc
386#
387# alarms:
388# morning_alarm:
389# # Cron expression format: run every weekday at 7 AM
390# when: '0 7 * * 1-5'
391# media: ~/path/your_ringtone.mp3
392# audio_volume: 10 # 10%
393#
394# # Repeat the played media resource until the alarm is
395# # snoozed/dismissed (default: true)
396# media_repeat: true
397#
398# # Wait 5 minutes between a snooze and another run
399# snooze_interval: 300
400#
401# # After 10 minutes with no manual snooze/dismiss,
402# # stop the alarm
403# dismiss_interval: 600
404#
405# # Actions to be executed when the alarm goes on
406# actions:
407# - action: tts.say
408# args:
409# text: Good morning
410#
411# - action: light.hue.bri
412# args:
413# value: 1
414#
415# - action: light.hue.bri
416# args:
417# value: 140
418# transitiontime: 150
419#
420# one_shot_alarm:
421# # One-shot execution, with timestamp in ISO format
422# when: '2020-02-18T07:00:00.000000'
423# media: ~/path/your_ringtone.mp3
424# actions:
425# - action: light.hue.on
426#
427# timer:
428# # This alarm will execute the specified number of seconds
429# # after being initialized (5 minutes after the plugin has
430# # been initialized in this case)
431# when: 300
432# media: ~/path/your_ringtone.mp3
433# actions:
434# - action: light.hue.on
435###
436
437###
438# # Torrent plugin configuration, with the default directory that should be used
439# # to store downloaded files.
440#
441# torrent:
442# download_dir: ~/Downloads
443###
444
445###
446# # List of RSS/Atom subscriptions. These feeds will be monitored for changes and
447# # a `platypush.message.event.rss.NewFeedEntryEvent`
448# # (https://docs.platypush.tech/platypush/events/rss.html#platypush.message.event.rss.NewFeedEntryEvent)
449# # will be triggered when one of these feeds has new entries - you can subscribe
450# # the event to run your custom logic.
451#
452# rss:
453# # How often we should check for updates (default: 5 minutes)
454# poll_seconds: 300
455# # List of feeds to monitor
456# subscriptions:
457# - https://www.theguardian.com/rss/world
458# - https://phys.org/rss-feed/
459# - https://news.ycombinator.com/rss
460# - https://www.technologyreview.com/stories.rss
461# - https://api.quantamagazine.org/feed/
462###
463
464###
465# # The file monitor plugin can be used to track modifications to the
466# # filesystem - for example, when a file or a directory is modified, created
467# # or removed.
468#
469# file.monitor:
470# paths:
471# # Recursively monitor changes on the
472# # ~/my-images folder that include all the files
473# # matching a JPEG extension in case-insensitive
474# # mode, excluding those whose name starts with
475# # tmp_ and all the files contained in the
476# # __MACOSX folders
477# - path: ~/my-images
478# recursive: true
479# case_sensitive: false
480# regexes:
481# - '.*\\.jpe?g$'
482# ignore_patterns:
483# - '^tmp_.*'
484# ignore_directories:
485# - '__MACOSX'
486###
487
488###
489# # Example configuration of a weather plugin
490#
491# weather.openweathermap:
492# token: secret
493# lat: lat
494# long: long
495###
496
497###
498# # You can add IFTTT integrations to your routines quite easily.
499# #
500# # Register an API key for IFTTT, paste it here, and you can run an
501# # `ifttt.trigger_event` action to fire an event on IFTTT.
502# #
503# # You can also create IFTTT routines that call your Platypush instance, by
504# # using Web hooks (i.e. event hooks that subscribe to
505# # `platypush.message.event.http.hook.WebhookEvent` events), provided that the
506# # Web server is listening on a publicly accessible address.
507#
508# ifttt:
509# ifttt_key: SECRET
510###
511
512###
513# # The `http.webpage` integration comes with the mercury-parser JavaScript
514# # library. It allows you to "distill" the content of a Web page and export it
515# # in readable format (in simplified HTML, Markdown or PDF).
516#
517# http.webpage:
518###
519
520###
521# # The Bluetooth integration allows you to scan Bluetooth devices, hook events
522# # when Bluetooth devices are detected/lost, and it natively supports several
523# # device types that can be controlled or monitored via API or UI.
524#
525# bluetooth:
526# poll_interval: 30
527###
528
529###
530# # Example configuration of the zigbee.mqtt integration.
531# # This integration listens for the events pushed by zigbee2mqtt service to an
532# # MQTT broker. It can forward those events to native Platypush events (see
533# # https://docs.platypush.tech/platypush/events/zigbee.mqtt.html) that you can
534# # build automation routines on. You can also use Platypush to control your
535# # Zigbee devices, either through the Web interface or programmatically through
536# # the available plugin actions.
537#
538# zigbee.mqtt:
539# # Host of the MQTT broker
540# host: my-mqtt-broker
541# # Listen port of the MQTT broker
542# port: 1883
543# # Base topic, as specified in `<zigbee2mqtt_dir>/data/configuration.yaml`
544# topic_prefix: zigbee2mqtt
545###
546
547###
548# # Example configuration of the zwave.mqtt integration.
549# # This integration listens for the events pushed by ZWaveJS service to an MQTT
550# # broker. It can forward those events to native Platypush events (see
551# # https://docs.platypush.tech/platypush/events/zwave.html) that you can build
552# # automation routines on.
553# # You can also use Platypush to control your Z-Wave devices, either through the
554# # Web interface or programmatically through the available plugin actions.
555#
556# zwave.mqtt:
557# # Host of the MQTT broker
558# host: my-mqtt-broker
559# # Listen port of the MQTT broker
560# port: 1883
561# # Gateway name, usually configured in the ZWaveJS-UI through `Settings ->
562# # MQTT -> Name`
563# name: zwavejs2mqtt
564# # The prefix of the published topics, usually configured in the ZWaveJS-UI
565# # through `Settings -> MQTT -> Prefix`.
566# topic_prefix: zwave
567###
568
569### --------------------
570### Camera configuration
571### --------------------
572
573###
574# # There are several providers for the camera integration - you can choose
575# # between ffmpeg, gstreamer, PiCamera etc., and they all expose the same
576# # interface/configuration options.
577# #
578# # It is advised to use the ffmpeg integration, as it's the one that provides
579# # the highest degree of features and supported hardware.
580# #
581# # If the plugin is correctly configured, you can access your camera feed from
582# # the Platypush Web panel, programmatically start/stop recording sessions, take
583# # photos, get a feed stream URL etc.
584#
585# # The camera feed will be available at `/camera/<plugin>/video[.extension]`,
586# # for example `/camera/ffmpeg/video.mjpeg` for MJPEG (usually faster), or
587# # `camera/ffmpeg/video.mp4` for MP4.
588#
589# # You can also capture images by connecting to the
590# # `/camera/<plugin>/photo[.extension]`, for example `/camera/ffmpeg/photo.jpg`.
591#
592# camera.ffmpeg:
593# # Default video device to use
594# device: /dev/video0
595# # Default resolution
596# resolution:
597# - 640
598# - 480
599# # The directory that will be used to store captured frames/images
600# frames_dir: ~/Camera/Photos
601# # Default image scaling factors (default: 1, no scaling)
602# scale_x: 1.5
603# scale_y: 1.5
604# # Default rotation of the image, in degrees (default: 0, no rotation)
605# rotate: 90
606# # Grayscale mode (default: False):
607# grayscale: false
608# # Default frames per second (default: 16)
609# fps: 16
610# # Whether to flip the image along the horizontal axis (default: False)
611# horizontal_flip: false
612# # Whether to flip the image along the horizontal axis (default: False)
613# vertical_flip: false
614#
615# # -- Streaming options
616# # If `stream_on_start` is set to true, then camera streaming will start as
617# # soon as the application/plugin is started. Otherwise, only when the
618# # `camera.<plugin>.start_streaming` action is run. The camera will be
619# # streamed on the specified `bind_address` and `listen_port` in the
620# # specified `stream_format`. If `stream_format` is a video format (e.g.
621# # h264 or mkv) then you can play the raw camera stream through e.g.
622# # `vlc tcp://<address>:<listen_port>`.
623# # Alternatively, you can access the camera stream over HTTP at
624# # `http(s)://<address>:<http-port>/camera/<plugin>/video.<format>`.
625# # For example, for MJPEG stream (usually the fastest option over HTTP):
626# # `http://localhost:8008/camera/ffmpeg/video.mjpeg`.
627# # An HTTP stream is the safest option, as it has to go through the standard
628# # HTTP authentication process, while direct TCP access may expose your
629# # camera to unauthenticated access. If you decide to directly stream over
630# # TCP, make sure to carefully select the `bind_address`, add a firewall
631# # rule for the streaming port, and/or ensure that the device's port is only
632# # accessible from a safe network.
633# # stream_on_start: false
634# # bind_address: 0.0.0.0
635# # listen_port: 5000
636# # stream_format: h264
637###
638
639### -----------------
640### Sound integration
641### -----------------
642
643###
644# # The sound plugin allows you to stream from an audio source connected to the
645# # machine, play audio files or synthetic audio waves or MIDI sounds.
646#
647# # After enabling the plugin, you can access the audio stream at
648# # `/sound/stream[.extension]` (e.g. `/sound/stream.mp3`) if you want to get a
649# # live recording of the captured sound from the configured audio
650# # `input_device`.
651#
652# sound:
653# enabled: true
654###
655
656### -----------------------------------
657### Some examples of media integrations
658### -----------------------------------
659
660###
661# # Example configuration for the media.vlc plugin. You can replace `vlc` with
662# # `mpv`, `mplayer`, `omxplayer` or `gstreamer` if you want to use another
663# # player - the supported configuration option are the same across all these
664# # players.
665#
666# media.vlc:
667# # Volume level, between 0 and 100
668# volume: 50
669# # Where to store downloaded files
670# download_dir: ~/Downloads
671# # Play videos in fullscreen by default
672# fullscreen: True
673# # If youtube-dl or any compatible application is installed, play requested
674# # videos in this format by default. Default: `best`.
675# youtube_format: 'mp4[height<=?480]'
676# # Extra arguments to pass to the executable. --play-and-exit may be a good
677# # idea with VLC, so the player terminates upon stop instead of lingering in
678# # the background.
679# args:
680# - --play-and-exit
681# # List of directories to search for media files. The media files in these
682# # folders can be searched through the `media.<player>.search` command, or
683# # through the Web interface.
684# media_dirs:
685# - /mnt/hd/media/movies
686# - /mnt/hd/media/series
687# - /mnt/hd/media/videos
688# - ~/Downloads
689###
690
691###
692# # Example configuration for the media.chromecast plugin, see
693# # https://docs.platypush.tech/en/latest/platypush/plugins/media.chromecast.html
694# # You can easily install the dependencies through pip install 'platypush[chromecast]'
695#
696# media.chromecast:
697# chromecast: Living Room TV
698###
699
700###
701# # Example Kodi configuration. This makes it possible to control and query a
702# # Kodi instance, from your automation hooks, from the Platypush APIs or from
703# # the Platypush Web interface. It requires you to enable the JSON API service
704# # from Kodi's settings.
705#
706# media.kodi:
707# host: localhost
708# http_port: 8080
709# username: kodi
710# password: secret
711###
712
713###
714# # Example configuration for a Plex media server. This integration makes it
715# # possible to navigate and search media items from your Plex library in the
716# # media UI.
717#
718# media.plex:
719# server: localhost
720# username: plex
721# password: secret
722###
723
724###
725# # Jellyfin media server configuration.
726#
727# media.jellyfin:
728# server: https://media.example.com
729# api_key: secret
730###
731
732### ---------------------
733### Sensors configuration
734### ---------------------
735
736###
737# # The serial plugin can be used to read sensor data from a device connected
738# # over serial/USB interface.
739# #
740# # It can be used, for example, to connect to an Arduino or ESP device over
741# # serial port, where the remote microcontroller periodically sends sensor data
742# # over the serial interface.
743# #
744# # The data can be sent on the wire either as raw string-encoded numbers (one
745# # per line), or (better) in JSON format. For example, you can program your
746# # microcontroller to periodically send JSON strings like these when you get new
747# # readings from your sensors:
748# #
749# # {"temperature": 25.0, "humidity": 20.0, "smoke": 0.01, "luminosity": 45}
750# #
751# # The JSON will be automatically unpacked by the application, and the relevant
752# # `platypush.message.event.sensor.SensorDataChangeEvent` events will be
753# # triggered when the data changes - you can subscribe to them in your custom
754# # hooks.
755#
756# serial:
757# # The path to the USB interface with e.g. an Arduino or ESP microcontroller
758# # connected.
759# # A way to get a deterministic path name on Linux, instead of
760# # `/dev/ttyUSB<n>`, can be the following:
761# #
762# # - Get the vendor and product ID of your device via e.g. `lsusb`. For
763# # example, for an Arduino-compatible microcontroller:
764# #
765# # Bus 001 Device 008: ID 1a86:7523 QinHeng Electronics CH340 serial converter
766# #
767# # - In the case above, `1a86` is the vendor ID and `7523` is the product
768# # ID. Create a new udev rule for it, so every time the device is
769# # connected it will also be symlinked to e.g. `/dev/arduino`:
770# #
771# # echo 'SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", SYMLINK+="arduino"' | \
772# # sudo tee /etc/udev/rules.d/98-usb-serial.rules
773# device: /dev/ttyUSB0
774# # How often the interface should be polled for updates, in seconds
775# poll_interval: 1
776# # The tolerance argument can be used to tune when you want to be notified
777# # of data changes through `SensorDataChangeEvent` events. In the case
778# # below, if the microcontroller sends two consecutive temperature reads,
779# # one for 22.0 and one for 22.2, then only one `SensorDataChangeEvent` will
780# # be triggered (for the first read), since the absolute value of the
781# # difference between the two events is less than the configured tolerance.
782# # However, if the device sends two temperature reads, one for 22.0 and one
783# # for 22.7, then two `SensorDataChangeEvent` events will be triggered.
784# # The tolerance for all the metrics is set to a value close to zero by
785# # default - i.e. any read, unless it's exactly the same as the previous
786# # one, will trigger a new event.
787# tolerance:
788# temperature: 0.5
789# humidity: 0.75
790# luminosity: 5
791#
792# # If a threshold is defined for a sensor, and the value of that sensor goes
793# # below/above that temperature between two reads, then a
794# # `SensorDataBelowThresholdEvent` or a `SensorDataAboveThresholdEvent` will
795# # be triggered respectively.
796# thresholds:
797# temperature: 25.0
798###
799
800###
801# # Alternatively to the serial plugin, you can also use the arduino plugin if
802# # you want to specifically interface with Arduino.
803# #
804# # This plugin won't require you to write any logic for your microcontroller.
805# # However, it requires your microcontroller to be flash with the Firmata
806# # firmware, which allows programmatic external control.
807# #
808# # Note that the interface of this plugin is basically the same as the serial
809# # plugin, and any other plugin that extends `SensorPlugin` in general.
810# # Therefore, poll_interval, tolerance and thresholds are supported here too.
811#
812# arduino:
813# board: /dev/ttyUSB0
814# # name -> PIN number mapping (similar for digital_pins).
815# # It allows you to pick a common name for your PINs that will be used in
816# # the forwarded events.
817# analog_pins:
818# temperature: 7
819#
820# tolerance:
821# temperature: 0.5
822#
823# thresholds:
824# temperature: 25.0
825###
826
827###
828# # Another example: the LTR559 is a common sensor for proximity and luminosity
829# # that can be wired to a Raspberry Pi or similar devices over SPI or I2C
830# # interface. It exposes the same base interface as all other sensor plugins.
831#
832# sensor.ltr559:
833# poll_interval: 1.0
834# tolerance:
835# light: 7.0
836# proximity: 5.0
837#
838# thresholds:
839# proximity: 10.0
840###
841
842### -----------------------------------------
843### Example configuration of the mail plugin.
844### -----------------------------------------
845#
846# mail:
847# # Display name to be used for outgoing emails. Default:
848# # the `from` parameter will be used from :meth:`.send`,
849# # and, if missing, the username from the account configuration
850# # will be used.
851# display_name: My Name
852#
853# # How often we should poll for updates (default: 60 seconds)
854# poll_interval: 60
855#
856# # Connection timeout (default: 20 seconds)
857# # Can be overridden on a per-account basis
858# timeout: 20
859#
860# accounts:
861# - name: "My Local Account"
862# username: me@mydomain.com
863# password: my-password
864#
865# # The default flag sets this account as the default one
866# # for mail retrieval and sending if no account is
867# # specified on an action. If multiple accounts are set
868# # and none is set as default, and no account is specified
869# # on an action, then the first configured account will be
870# # used.
871# default: true
872# # Domain to be used for outgoing emails. Default: inferred
873# # from the account configuration
874# domain: example.com
875#
876#
877# # Alternatively, you can run an external command
878# # to get the password
879# # password_cmd: "pass show mail/example.com"
880#
881# # Path to a custom certfile if the mail server uses a
882# # self-signed certificate
883# # certfile: /path/to/certfile
884#
885# # Path to a custom keyfile if the mail server requires
886# # client authentication. It requires certfile to be set
887# # too
888# # keyfile: /path/to/keyfile
889#
890# incoming:
891# # Supported protocols: imap, imaps
892# server: imaps://mail.example.com:993
893#
894# outgoing:
895# # The `incoming` and `outgoing` configurations can
896# # override the global `username` and `password` and
897# # other authentication parameters of the account
898# username: me
899# password: my-smtp-password
900#
901# # Supported protocols: smtp, smtps, smtp+starttls,
902# server: smtps://mail.example.com:465
903#
904# # These folders will be monitored for new messages
905# monitor_folders:
906# - All Mail
907###
908
909### --------------------------------
910### Some text-to-speech integrations
911### --------------------------------
912
913###
914# # `tts` is the simplest TTS integration. It leverages the Google Translate open
915# # "say" endpoint to render text as audio speech.
916#
917# tts:
918# # The media plugin that should be used to play the audio response
919# # The default language of the voice
920# language: en-gb
921###
922
923###
924# # `tts.google` leverages Google's official text-to-speech API to render audio
925# # speech from text.
926# #
927# # Install its dependencies via 'pip install "platypush[google-tts]"'.
928# #
929# # Like all other Google integrations, it requires you to register an app on the
930# # Google developers console, create an API key, and follow the instruction
931# # logged on the next restart to give your app the required permissions to your
932# # account.
933#
934# tts.google:
935# # The default language of the voice
936# language: en-US
937# # The gender of the voice (MALE or FEMALE)
938# gender: FEMALE
939# # The path to the JSON file containing your Google API credentials
940# credentials_file: '~/.credentials/platypush/google/platypush-tts.json'
941###
942
943###
944# # This TTS integration leverages mimic3, an open-source TTS Web server
945# # developed by Mycroft (RIP).
946# #
947# # Follow the instructions at
948# # https://docs.platypush.tech/platypush/plugins/tts.mimic3.html to quickly
949# # bootstrap a mimic3 server.
950#
951# tts.mimic3:
952# # The base URL of the mimic3 server
953# server_url: http://127.0.0.1:59125
954# # Path of the default voice that should be used
955# voice: 'en_US/vctk_low'
956###
957
958## ----------
959## Procedures
960## ----------
961
962# Procedures are lists of actions that are executed sequentially.
963#
964# This section shows how to define procedures directly in your YAML
965# configuration file(s). However, you can also put your procedures into Python
966# scripts inside of the `<config-dir>/scripts` directory if you want access to
967# a full-blown Python syntax. They will be automatically discovered at startup
968# and available to the application.
969#
970# You can also access Python variables and evaluate Python expressions by using
971# `${}` context expressions.
972#
973# The `context` special variable is a name->value dictionary containing the
974# items returned from previous actions. For example, if an action returned
975# `{"status": "ok", "temperature": 21.5}`, then the following actions can access
976# those variables through `${context["status"]}` or
977# `${context["temperature"]}`, or simply `${status}` and `${temperature}`,
978# respectively.
979#
980# You can also add statements like `- if ${temperature > 20.0}` or
981# `- for ${temp in temperature_values}` in your procedures.
982#
983# Besides the `context` variables, the following special variables are also
984# available to the `${}` constructs when running a procedure:
985#
986# - `output`: It contains the parsed output of the previous action.
987# - `errors`: It contains the errors of the previous action
988# - `event`: If the procedure is an event hook (or it is executed within an
989# event hook), it contains the event that triggered the hook
990
991###
992# # An example procedure that can be called when you arrive home.
993# #
994# # You can run this procedure from the Platypush `execute` Web panel, or
995# # programmatically by sending a JSON request to your Web server (or to the
996# # `/ws/requests` Websocket route, or to the TCP backend)
997# #
998# # curl -XPOST \
999# # -H "Authorization: Bearer $YOUR_TOKEN" \
1000# # -d '{"type": "request", "action": "procedure.at_home"}'
1001# #
1002# # A use-case can be the one where you have a Tasker automation running on your
1003# # Android device that detects when your phone enters or exits a certain area,
1004# # and sends the appropriate request to your Platypush server.
1005#
1006# procedure.at_home:
1007# # Set the db variable AT_HOME to 1.
1008# # Variables are flexible entities with a name and a value that will be
1009# # stored on the database and persisted across sessions.
1010# # You can access them in other procedures, scripts or hooks and run
1011# # custom logic on the basis of their value.
1012# - action: variable.set
1013# args:
1014# AT_HOME: 1
1015#
1016# # Check the luminosity level from e.g. a connected LTR559 sensor.
1017# # It could also be a Bluetooth, Zigbee, Z-Wave, serial etc. sensor.
1018# - action: sensor.ltr559.get_measurement
1019#
1020# # If it's below a certain threshold, turn on the lights.
1021# # In this case, `light` is a parameter returned by the previous response,
1022# # so we can directly access it here through the `${}` context operator.
1023# # ${light} in this case is equivalent to ${context["light"]} or
1024# # ${output["light"]}.
1025# - if ${int(light or 0) < 110}:
1026# - action: light.hue.on
1027#
1028# # Say a welcome home message
1029# - action: tts.mimic3.say
1030# args:
1031# text: Welcome home
1032#
1033# # Start the music
1034# - action: music.mpd.play
1035###
1036
1037###
1038# # Procedure that will be execute when you walk outside your home.
1039#
1040# procedure.outside_home:
1041# # Unset the db variable AT_HOME
1042# - action: variable.unset
1043# args:
1044# name: AT_HOME
1045#
1046# # Stop the music
1047# - action: music.mpd.stop
1048#
1049# # Turn off the lights
1050# - action: light.hue.off
1051###
1052
1053###
1054# # Procedures can also take optional arguments. The example below shows a
1055# # generic procedure that broadcasts measurements from a sensor through an
1056# MQTT broker.
1057#
1058# # A listener on this topic can react to an `MQTTMessageEvent` and, for
1059# # example, store the event on a centralized storage.
1060# #
1061# # See the event hook section below for a sample hook that listens for messages
1062# # sent by other clients using this procedure.
1063#
1064# procedure.send_sensor_data(name, value):
1065# - action: mqtt.send_message
1066# args:
1067# topic: platypush/sensors
1068# host: my-mqtt-broker
1069# port: 1883
1070# msg:
1071# name: ${name}
1072# value: ${value}
1073# source: ${Config.get("device_id")}
1074###
1075
1076## -------------------
1077## Event hook examples
1078## -------------------
1079
1080# Event hooks are procedures that are run when a certain condition is met.
1081#
1082# Check the documentation of your configured backends and plugins to see which
1083# events they can trigger, and check https://docs.platypush.tech/events.html
1084# for the full list of available events with their schemas.
1085#
1086# Just like procedures, event hooks can be defined either using the YAML
1087# syntax, or in Python snippets in your `scripts` folder.
1088#
1089# A YAML event hook consists of two parts: an `if` field that specifies on
1090# which event the hook will be triggered (type and attribute values), and a
1091# `then` field that uses the same syntax as procedures to specify a list of
1092# actions to execute when the event is matched.
1093
1094###
1095# # This example is a hook that reacts when an `MQTTMessageEvent` is received on
1096# # a topic named `platypush/sensor` (see `send_sensor_data` example from the
1097# # procedures section).
1098# #
1099# # It will store the event on a centralized Postgres database.
1100# #
1101# # Note that, for this event to be triggered, the application must first
1102# # subscribe to the `platypush/sensor` topic - e.g. by adding `platypush/sensor`
1103# # to the active subscriptions in the `mqtt` configurations.
1104#
1105# event.hook.OnSensorDataReceived:
1106# if:
1107# type: platypush.message.event.mqtt.MQTTMessageEvent
1108# topic: platypush/sensor
1109# then:
1110# - action: db.insert
1111# args:
1112# engine: postgresql+pg8000://dbuser:dbpass@dbhost/dbname
1113# table: sensor_data
1114# records:
1115# - name: ${msg["name"]}
1116# value: ${msg["value"]}
1117# source: ${msg["source"]}
1118###
1119
1120###
1121# # The example below is a hook that reacts when a `NewPlayingTrackEvent` event
1122# # is received and synchronize the listening activity to the users' Last.fm
1123# # profile (it requires the `lastfm` plugin and at least a music plugin
1124# # enabled, like `music.mpd`).
1125#
1126# event.hook.OnNewMusicActivity:
1127# if:
1128# type: platypush.message.event.music.NewPlayingTrackEvent
1129# then:
1130# - if ${track.get('artist') and track.get('title')}:
1131# - action: lastfm.scrobble
1132# args:
1133# artist: ${track['artist']}
1134# title: ${track['title']}
1135##
1136
1137###
1138# # The example below plays the music on mpd/mopidy when your voice assistant
1139# # triggers a speech recognized event with "play the music" content.
1140#
1141# event.hook.PlayMusicAssistantCommand:
1142# if:
1143# type: platypush.message.event.assistant.SpeechRecognizedEvent
1144# # Note that basic regexes are supported for `SpeechRecognizedEvent`,
1145# # so the hook will be triggered both if you say "play the music" and
1146# # "play music"
1147# phrase: "play (the)? music"
1148# then:
1149# - action: music.mpd.play
1150###
1151
1152###
1153# # This will turn on the lights when you say "turn on the lights"
1154#
1155# event.hook.TurnOnLightsCommand:
1156# if:
1157# type: platypush.message.event.assistant.SpeechRecognizedEvent
1158# phrase: "turn on (the)? lights?"
1159# then:
1160# - action: light.hue.on
1161###
1162
1163###
1164# # The WebhookEvent is a special type of event. It allows you to dynamically
1165# # register a Web hook that can be invoked by other clients, if the HTTP backend
1166# # is active.
1167# #
1168# # In this case, we are registering a hook under `/hook/test-hook` that accepts
1169# # POST requests, gets the body of the requests and logs it.
1170# #
1171# # NOTE: Since Web hooks are supposed to be called by external (and potentially
1172# # untrusted) parties, they aren't designed to use the standard authentication
1173# # mechanism used by all other routes.
1174# #
1175# # By default they don't have an authentication layer at all. You are however
1176# # advised to create your custom passphrase and checks the request's headers or
1177# # query string for it - preferably one passphrase per endpoint.
1178#
1179# event.hook.WebhookExample:
1180# if:
1181# type: platypush.message.event.http.hook.WebhookEvent
1182# hook: test-hook
1183# method: POST
1184# then:
1185# # Check the token/passphrase
1186# - if ${args.get('headers', {}).get('X-Token') == 'SECRET':
1187# - action: logger.info
1188# args:
1189# msg: ${data}
1190###
1191
1192### -------------
1193### Cron examples
1194### -------------
1195
1196###
1197# # Cronjobs allow you to execute procedures at periodic intervals.
1198# # Standard UNIX cron syntax is supported, plus an optional 6th indicator
1199# # at the end of the expression to run jobs with second granularity.
1200# # The example below executes a script at intervals of 1 minute.
1201#
1202# cron.TestCron:
1203# cron_expression: '* * * * *'
1204# actions:
1205# - action: shell.exec
1206# args:
1207# cmd: ~/bin/myscript.sh
1208###