Skip to main content

Managing a shopping list with Kalliope

Introduction

As promised in my todotxt neuron post, here is a post about how I managed my todolist via Kalliope !

As it's compatible with todotxt format, you can still use the same file as kalliope to manage your todolists.

Installation

Install the neuron

.. code:: bash

kalliope install --git-url https://github.com/bacardi55/kalliope-todotxt.git

Configuration

First things first, you need a todo file (empty or not) that kalliope will use.

For example, I created a simple file in my root directory:

.. code:: bash

touch ~/todo.txt

Then you need to choose the name of your project so item can be filtered. It will add +project in your todoline (but won't say it at loud).

In this example, I've choosen grocery

Add item

First thing we need, is to add item to our list. To do so, create a new brain file todotxt.yml in your brain folder and put:

.. code:: yaml

{% raw %}
  - name: "add-item-to-grocery-list"
    signals:
      - order: "think about buying {{content}}"
    neurons:
      - todotxt:
          action: "add"
          todotxt_file: "~/todo.txt"
          action: "add"
          project: "grocery"
          args:
              - content
          say_template: "I added {{added_task.task}} to the grocery list"
{% endraw %}

Here, no need of a template, Kalliope return the item added in the list.

Now, you should be able to look into the todo.txt file and see the added line. Eg: if I said "think about buying milk", I'll have a new line in my todo.txt file like this: .. code:: bash

milk +grocery
List items

Now that we have added an item, we want to be able to hear them from kalliope before going shopping.

Add this in your brain file:

.. code:: yaml

  - name: "Get-grocery-items"
    signals:
      - order: "grocery list"
    neurons:
      - todotxt:
          action: "get"
          todotxt_file: "~/todo.txt"
          project: "grocery"
          file_template: "templates/grocery.j2"

Then, create the template file (here templates/grocery.j2) and add:

.. code:: jina

{% raw %}
{% if count > 0 %}
    Your grocery list contains:
    {% for task in task_list %}
        {{ task.text  }}
    {% endfor %}
{% else %}
    You don't have any item in your list
{% endif %}
{% endraw %}

And here we go! You can now go shopping!

Delete items

Once your shopping is done, you want to empty the list, via Kalliope of course!

Add this to your brain file:

.. code:: yaml

{% raw %}
  - name: "clear-shopping-list"
    signals:
      - order: "Clear the shopping list"
    neurons:
      - todotxt:
          action: "del"
          todotxt_file: "~/todo.txt"
          project: "grocery"
          say_template: "{{count}} items have been deleted"
{% endraw %}

And voilà!

Send

Wait wait wait, you can't send it ?

Hmm, I thought about it, but I didn't thought that it should be done by the todotxt neuron. It's role is only to manage the text file. Adding a send method would break that rule and make it too customized.

So… no getting that list on my phone ? I have a bad memory you know…

Of course you can, and of course I'll give you the tip :)

First, I decided to stay simple, no mail server heavy configuration or things like that. You can use sendmail, postfix, ssmtp to send email, this tip should still work.

For this example, I'm using ssmtp to connect to a remote smtp server (own by me) so no big configuration.

Just edit the /etc/ssmtp/ssmtp.conf file

.. code:: bash

root=mail@example.com
AuthUser=mail@example.com
AuthPass=YourMailPassword
mailhub=mail.example.com:465
UseTLS=YES
rewriteDomain=example.com
FromLineOverride=YES

and of course change the example.com :).

There are a lot of documentation out there if you need to set it up to gmail.

So your system can send mail now. I did create a small python script that is like a wrapper to send mail from the system.

The script can be found here

Usage:

.. code:: bash

usage: sendmail.py [-h] [-f FROMEMAIL] [-t TO] [-s SUBJECT] [-b BODY]
                   [-c COMMAND] [-v]

optional arguments:
  -h, --help            show this help message and exit
  -f FROMEMAIL, --fromemail FROMEMAIL
                        From email address
  -t TO, --to TO        To email address
  -s SUBJECT, --subject SUBJECT
                        Email subject
  -b BODY, --body BODY  Email body, used if -c is not present
  -c COMMAND, --command COMMAND
                        Command to generate text body
  -v, --verbose         Verbose mode

Ok, so now I have a configured ssmtp and a script to send mail easily via the command line.

I created this one liner bash script that will get (via grep) the content in the todo file and use it as the body of the email, like this:

.. code:: bash

##!/bin/bash
/home/pi/kalliope_config/script/sendmail.py -s="[kalliope] Grocery list" -b="`grep +grocery ~/todo.txt`"

I named it mail_grocery.sh.

Then, I just leverage the script neuron to fire the bash script

.. code:: yaml

  - name: "send-shopping-list"
    signals:
      - order: "send me the shopping list"
    neurons:
      - script:
          path: "script/mail_grocery.sh"

And you should be all set !

Entering the domotic game

Introduction

So far, most of the things I do with Kalliope could be considered as not really domitic (maybe more domogeek ^^).

Indeed, so far I use Kalliope to:

The last 2 items could be considered as domotic, but I consider them as media management, but the line is grey :)

Domotic

what for?

Usage are legions and I don't intend to describe all of them here, just the one I'm going to use. Bear in mind than I'm just starting so my knowledge is limited and the devices I have are not numerous :).

I have several ideas to start with, like managing internal sensors (temp, light, motion detector, …) or managing switches (Lamp, electric plug, …)

How:

The protocol: Z-wave

But first, I needed to find the basic of all this: How to manage these devices from a central control point. I read online some documentation, about protocol and devices and finally end up choosing device compatible with the z-wave protocol, as there is the openzwave opensource lib that seems to work well. Main issue of Z-wave is that the company behind it are owner of the z-wave chip.

I let you read online additional info on z-wave if you wish, there are a lot about it.

The main controller: Domoticz

So I ended up buying a usb stick z-wave controller and a z-wave multi sensor (temp/hum, light, motion detection) to start poking at it. But I still needed an app to manage all the z-wave devices.

For this, 2 solutions:

  • Create a neuron that leverage the openzwave python library
  • Use a tool that manage domotic devices

I think that the simplest, yet most powerful approach was to choose the 2nd option, and choose a software that was exactly meant to manage domotic device. I could have choose several: jeedom, openhab, Home-Assistant.io, …

I ended up choosing Domoticz, very light and powerful app in C++ with a web app and a mobile app. It was very easy to install on an old rpiB+ and to setup my z-wave sensor.

It also provide APIs to do a lot of actions so that kalliope could send action :)

APIs provide options to (non exhaustive, go to their doc page for full API endpoints):

  • Get device status (and value): Important for me to get metric from sensor
  • Set on/off on device: I'll soon have a zwave electrig plug, and I want to be able to switch it on and off via kalliope
  • Get / Set scene/groups state: Scene and groups are option in domoticz to regroup devices together (group mean all device has same state (on or off) and group state can be change. Scene has only one state, but devices can have different states).

That's the main I'll start poking at, in that order!

Kalliope integration
Pymoticz

I did find online an old python code to manage domoticz. I also found a more recent fork of it here that worked well.

Only issue is that is was forcing the use of http and didn't allow https. So I forked it to add https support. There is pull request here to merge it.

Kalliope Neuron

As you would have guess, a neuron is coming up. You can find it in a draft mode on github. For now, it is very limited but in development. It does include directly the pymoticz library so no manual addition needed there.

For now, you can only request data value from a device. So for example, I can retrieve the temperature and the light level from the sensor.

Brain example

.. code:: yaml

---
  - name: "domoticz-get-temp-living-room"
    signals:
      - order: "living room temperature"
    neurons:
      - domoticz:
          host: "{{domoticz_host}}"
          action: "get_device"
          device: "6"
          ssl_verify: "False"
          say_template: "Living temperature is {{devices[0]['Temp'] | safe}} degrees and humidity is {{devices[0]['Humidity'] | safe}} %"
  - name: "domoticz-get-lux-living-room"
    signals:
      - order: "brightness in living room"
    neurons:
      - domoticz:
          host: "{{domoticz_host}}"
          action: "get_device"
          device: "5"
          ssl_verify: "False"
          say_template: "Living room brightness is {{devices[0]['Data'] | safe}}"

What's next

As I said above, there are a lot to be able to do: set on/off devices, get / set scenes and groups, … A lot of fun to have marrying Kalliopé and domoticz :)

Stay tuned!

Todotxt, a neuron to manage todolist compatible with todotxt format!

Introduction

This neuron allow Kalliope to manage todolists. It leverages the todotxt methodology and rules.

With the current state of the neuron, you'll be able to list (and filter), add and delete tasks in your todolists.

Why todotxt ?

Ways of managing a todolist with Kalliope:

As of no todolist neuron exists so far, I needed to created this feature from scratch. I had the following possibilities:

All of them have advantages and drawbacks, but I had personal requirements:

  • Open Source software (what else…)
  • Data privacy (keeping my todolist mine)
  • Simplicity (I won't manage reporting, diagram and very complex tasks via Kalliope)

The choice

Looking at the lists of options and requirements above, only 2 options were attractive to me:

  • Taskwarrior + taskwarrior server: this was my main idea for a long time, as a previous long time user of Taskwarrior. This todolist tool is extremely powerful and can manage all aspects of a todolist as well as creating reports etc. Cli is very complete (and can be complex if you have a lot of arguments / commands) but it for me the "Rolls-Royce" of cli todolist tools. The server setup and a full configuration can takes a bit of time though.
  • Simple text file: I like the idea but lacked flexibility. It would have meant simple file per todo list (one for groceries, one for reminders, …), but the integration with Kalliope would be simple ass reading/writing a text file. As well, a text file can be read on any devices without a required application being installed. Sharing text file todolists is simple (eg: mail, scp, rsync, … ) But that will be part of another blog post about how I manage my grocery lists via Kalliope.

The solution: todotxt !

If I had 2 words to describe todotxt, it would be : simply powerful

Todotxt is simple concept (not even an software per say) to manage todolists via a single text files, with only a very small set of rules for writing tasks in it. I encourage you to go to their website and learn about it, it will take you 5 minutes to understand the full concept. You can find the rules set here and an example of a todotxt file here

If you already use todotxt or like its simplicity, this neuron is for you.

As well, if you don't really care about sharing Kalliope's todolist on the cloud or with your other devices and use other todolist app for your own work/personal todolist, you can of course leverage this neuron as well :)

The neuron

What it does

  • Manage tasks based on todotxt model: priority, project, context, completeness
  • List / filter items from todotxt files
  • Add elements to list (with arguments like priority and projects)

What it could do in future release

  • Get / Delete searched entry
  • Mark as complete / Update tasks (instead of delete)
  • Manage multi projects and contexts in order.

Installation

Usual Kallipoe way:

.. code:: bash

kalliope start install --git-url https://github.com/bacardi55/kalliope-todotxt.git

Configuration

As usual, the README is the most up to date documentation about arguments / return values.

arguments:
parameter required default choices comments
action yes 'get', 'add' or 'del' The action to launch
todotxt_file yes String The path to the todotxt file
priority No 'A', 'B' or 'C' The priority of the task
project No String The project of the task
context No String The context of the task
complete No False Boolean: False or True If the task is complete or not
content No String The content of the task

Additional notes:

  • If action is 'add':
  • Content argument is mandatory
  • Priority/context/complete/projects will be added in the raw line in text file
  • If action is 'get', adding priority / project / context will filter the results (see brain example below)
  • If action is 'del', every tasks that match the given priority/project/context will be deleted.
Return values:

Only necessary when the neuron use a template to say something

name description type sample
action The action launched string 'get', 'del' or 'add'
task_list list of tasks (for get action only) list of tasks [task1, taks2, task3].
count The number of returned element Integer 2
added_task string value Task object¹ Task object¹

Additional notes:

  • If action is 'get':
  • Count contains the number of return tasks in tasks_lists
  • Task_lists contains the list of task object¹
  • add_task is unset
  • If action is 'del':
  • Count contains the number of deleted tasks
  • added_task is unset
  • task_list is unset
  • If action is 'add':
  • Count is unset
  • added_task contain a Task object¹
  • task_list is empty

Task Object: The task object contains the following properties:

  • Task.raw: the raw line representing the task in the todotxt file.
  • Task.task_id: The task id (number of line)
  • Task.task: The cleaned text of a text
  • Task.priority: The priority
  • Task.project: A list of project name
  • Task.context = A list of context name
  • Task.creation_date: Creation date if precised
  • Task.complete: Is the task complete?
  • Task.completion_date: Completion date if completed task
  • Task.due_date: Due date if precised.

You can reuse all these properties in template_file or file_template for each task objects (added_task or each element of task_list).

Brain examples

Get tasks, no filter.

.. code:: bash

  - name: "Get-all-tasks"
    signals:
      - order: "Get all my tasks"
    neurons:
      - todotxt:
          action: "get"
          todotxt_file: "resources/neurons/todotxt/samples/todo.txt"
          file_template: "templates/en_todotxt.j2"

Get tasks with specific filters

.. code:: yaml

  - name: "Get-specific-items"
    signals:
      - order: "Get my super list"
    neurons:
      - todotxt:
          action: "get"
          todotxt_file: "resources/neurons/todotxt/samples/todo.txt"
          project: "project"
          priority: "A"
          context: "context"
          complete: False
          file_template: "templates/en_todotxt.j2"

Add item to list

.. code:: yaml

{% raw %}
  - name: "add-item-to-super-list"
    signals:
      - order: "add {{content}} to the super list"
    neurons:
      - todotxt:
          action: "add"
          todotxt_file: "resources/neurons/todotxt/samples/todo.txt"
          project: "project"
          priority: "A"
          context: "context"
          complete: False
          args:
              - content
          say_template: "Task {{added_task.task}} has been added to the super project with priority {{added_task.priority}}"
{% endraw %}

You could also add arguments with value coming from voice order directly:

.. code:: yaml

{% raw %}
  - name: "add-item-to-super-list"
    signals:
      - order: "add {{content}} to the {{project}} list with priority {{priority}} and context {{context}}"
    neurons:
      - todotxt:
          action: "add"
          todotxt_file: "resources/neurons/todotxt/samples/todo.txt"
          complete: False
          args:
              - content
              - project: "project"
              - priority: "A"
              - context: "context"
          say_template: "Task {{added_task.task}} has been added to the super project with priority {{added_task.priority}}"
{% endraw %}

Remove items that match filters from global list.

.. code:: yaml

{% raw %}
  - name: "clear-super-list"
    signals:
      - order: "clear super list"
    neurons:
      - todotxt:
          action: "del"
          todotxt_file: "resources/neurons/todotxt/samples/todo.txt"
          project: "project"
          priority: "A"
          context: "context"
          complete: False
          say_template: "{{count}} items have been deleted"
{% endraw %}
Template examples

.. code:: jinja

{% raw %}
{% if count > 0 %}
    Your list contains:
    {% for task in task_list %}
        {{ task.text }}
    {% endfor %}
{% else %}
    You don't have any item in your list
{% endif %}

{% endraw %}

Or you can simply use the say_template argument, eg for adding a task:

.. code:: yaml

{% raw %}
say_template: "Task {{added_task.task}} has been added to the grocery list"
{% endraw %}

As usual, the sample directory contains more example of brains and templates.

Monitor and restart Kalliope via a led and a push button

Introduction

Tonight, I wanted to play a bit with my old raspberry pi B+ that I wasn't using anymore.

I wanted to use this rpi to monitor the temperature inside my house, and to do so I had to buy a sensor and a small electronic kit. While the temperature thing is not ready (even though the sensor is already plugged - but that will be another blog post), I had fun with 2 other elements of the electronic kit: A led and a push button.

The idea was simple: having a red LED that goes on when Kalliope is not responding anymore and a push button to restart the whole thing when needed.

So that if kalliope crashes, the red light will indicate me quickly and if I'm too lazy to go to my laptop to check what happened, I can simply press the button to restart every processes.

How

My setup is simple: I have 1 rpi with Kalliope installed on it, and another rpi with the component installed. I already have a lot working on the kalliope pi (kalliope and its API, mopidy and X with a touchscreen) so I used this other one.

What I did:

  • Create a script on kalliope rpi that restart everything
  • Create a script on the rpi B+ that starts / stops the led when needed
  • Create a script on the rpi B+ that listen to the push button

Installing the led and the button

I won't go in details here, I just followed some how to online and adapted to my needs. I invite you to do the same to setup your led and your button.

The scripts

Restart script

The restart script can be found here.

I manage kalliope and mopidy via the pi user because of some Pulseaudio issue, so that makes this script a bit ugly, but the idea is simple: kill running processes and restart them. Make sure this script is executable (chmod +x restart.sh) and where your user can access it.

The led script

The led script can be found here.

  • Try to access kalliope,. I choose to do it via the API. For now, it uses GET /synapses that is a bit heavy, but when this branch will get merged, it will be lighter via a simple GET / to get kalliope version
  • If Kalliope is off, turn on LED, if kalliope is on, turn off led
  • I also added a temporary file that contains previous status, so the script don't fire GPIO commands every minutes.
  • Launch this script via cron task (I choose every 2 minutes, but that's your choice)

Use the -h option of the script for help about script arguments.

The button script

This is the script that needs to be always running on rpi B+, so that when I push the button, it will fire the restart.sh via ssh. For this to work, the user from the rpiB+ needs to be able to connect over ssh without password (via ssh key)!

The script itself can be found here.

You need to have it running all the time, and for this, I created a systemd service file that be found here, thanks to my friend rustx!

All you need to do is to put it in /etc/systemd/system/ and enable it at boot: .. code:: bash

sudo systemctl enable emergency-button.service

Start it (sudo service emergency-button start) and check that everything is fine with the command sudo status emergency-button

You should have something like this:

.. code:: bash

 emergency-button.service
   Loaded: loaded (/etc/systemd/system/emergency-button.service; enabled)
   Active: active (running) since ven. 2017-02-24 22:55:08 UTC; 6min ago
 Main PID: 8349 (emergency_butto)
   CGroup: /system.slice/emergency-button.service
           └─8349 /usr/bin/python /home/pi/scripts/emergency_button.py

And normally everything should go smoothly, and each time the red led is on, just press the button to restart the whole shebang!

Ssmtp and password containing

Quick note as a "note to self", do not use # in AuthPass with ssmtp!

https://bugs.debian.org/cgi-bin/pkgreport.cgi?repeatmerged=no&src=ssmtp#_0_3_4

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=544018

Opening Tv show episode via Kalliope

Introduction

Today, a quick blog post about something I've put in place when I started playing with Kalliopé: asking kalliope to read videos from me.

The idea is simple: I have a raspberry pi in my living room plugged on my TV. On it kodi is installed and a hard drive with some tv shows episode on it (legally acquired!). The goal was to simply ask Kalliope to find a file on kodi hard drive and run it on kodi, eg: "Launch tv show friends episode 101"

The idea

First I asked myself if a neuron was useful or not here.

If I created a neuron, it would be either

  • A kodi neuron that need to implement their complex API
  • A neuron specific to my setup that no-one would reuse

Looking at my alternatives, I decided to manage it mainly via a simple shell script that would parse a simple text to find the name of the show, the episode and season. The script would then look over ssh to find the file name and then run a request against Kodi API to launch the file directly.

What does the shell script do

The script will receive in argument something like

  • is a string (eg: "friends")
  • is a number on 1 or 2 digit (eg: "1" or 12")
  • is a number always on 2 digit (eg: "01" or "21")

Based on this three information, the script will connect via ssh and run a find command on to find a file containing either:

  • the and "SE" (in this case, if season_number is lower than 10, the number will be put on 2 digit before)
  • the and "SEP" (in this case, if season_number is lower than 10, the number will be put on 2 digit before)
  • the and ""

This are the 2 uses cases for my file name. So a couple of example:

  • "friends 304" will search for file containing:
  • "friends" and "S03E04"
  • "friends" and "S03EP04"
  • "friends" and "304"
  • "friends 121" will search for file containing:
  • "friends" and "S01E21"
  • "friends" and "S01EP21"
  • "friends" and "121"
  • "friends 1005" will search for file containing:
  • "friends" and "S10E05"
  • "friends" and "S10EP05"
  • "friends" and "1005"

Once a file is found (first one), the Kodi API is used to start this file. The API command looks like this:

curl -g 'http://kodi/jsonrpc?request={"jsonrpc":"2.0","id":"1","method":"Player.Open","params":{"item":{"file":"'"$result_string"'"}}}'

Where $result_string is the name of file (and thus the result of the find/grep command) and kodi is the hostname of your kodi server.

Setup

The shell script

Enable ssh access

First, make sure the user that runs kalliope can connect via ssh without password (via ssh key or by manually opening an ssh-agent connection before launching kalliope)

I leave you find some tuto online about this kind of setup, there is already a lot of documentation!

Install the script

The full script can be found here.

Download it, make it executable (chmod +x find-episode.sh) and put it somewhere accessible by the user running kalliope.

(In my case, in a script directory in my kalliope starter kit

Create a brain file

This is my example but you can change to your needs:

.. code:: yaml

  - name: "Start-episode"
    signals:
      - order: "start episode {{ query }}"
    neurons:
      - shell:
          cmd: "/path/to/script/find-episode.sh "
          args:
             - query

The important thing is is to send the arguments as one query to the script that will manage the rest itself.

I could have created an order like start tv show {{tvshow}} season number {{season}} episode number {{number}} but the shell neuron didn't take arguments. I made an accepted PR to be able to send an argument to the shell script.

Maybe I should PR it again to add the ability to pass unlimited number of arguments that will be send to the shell script … But that then raise questions of orders, options, …

I hope this will work for you as well so you will be able to fire tv show episode without looking at your remote!

Kalliope - a poorsman log analyser

Introduction

Today, I wanted to have a quick overview of my Kalliope usage. I have more and more neurons available and more and more configured synapses so I thought it could be cool to start having some data.

I didn't want to put in place some heavy log analyser or sort, a simple bash script would do the trick.

Of course, I also wanted the output interface to be Kalliope as well (:

How

Generate log with kalliope

By default, logs are just the output of Kalliope and are not stored in logs. So instead of implementing something within Kalliope, I thought it would be easier to just launch kalliope and push the output into a log file. I also wanted to still be able to see the logs in the terminal I launched Kalliope with.

Normally, a simple

.. code:: bash

command | tee output.log

Should be enough, but because it is a python script, you actually need to launch Kalliope like this:

.. code:: bash

/usr/bin/python -u /usr/local/bin/kalliope start | tee -a kalliope.log

Read logs

I then created the simplest shell script possible. Can be found in my kalliope starter kit here.

.. code:: bash

##!/bin/bash

## You need to have kalliope logs available. To do so, I run kalliope like this:
## /usr/bin/python -u /usr/local/bin/kalliope start | tee -a kalliope.log
## So that logs are still displayed on standard output and in a log file

## Edit the audio variable text to use the variable as needed. Kalliope will read the content of the audio variable (output of the script)

LOG_FILE="/home/pi/kalliope_config/kalliope.log"

nb_trigger=$(cat "$LOG_FILE" | grep "Say something!" | wc -l)
nb_match=$(cat "$LOG_FILE" | grep "Order matched in the brain" | wc -l)
nb_audio_issue=$(cat "$LOG_FILE" | grep "Google Speech Recognition could not understand audio" | wc -l)
nb_no_synapse=$(cat "$LOG_FILE" | grep "No synapse match the captured order" | wc -l)

audio="As far as I remember, $nb_trigger vocal orders have been triggered, I didn't understood $nb_no_synapse of them and had an audio issue for $nb_audio_issue of them"

echo "$audio"

basically looking in the output the number of line matching some patterns triggered by Kalliopé.

The content of the audio variable is the text that will be read by Kalliope.

Create your brain

Now that you have the log generated, and the script to read them, you need to create the brain that will fire a simple shell script and read the output.

.. code:: yaml

  - name: "System-status"
    signals:
      - order: "Step into analysis mode, please"
    neurons:
      - shell:
          cmd: "sh script/poorsmanloganalyser.sh"
          say_template:
            - "{{output}}"

And now you can have some numbers (:

Kalliope GoogleMaps neuron

Introduction

If you follow me on twitter or github, you may have seen this new neuron coming, otherwise, let me introduce to you the Google Maps neuron :)

The goal as you can guess is to leverage the Google Maps API to get direction, distance or direction from an origin point to a destination (it doesn't handle multi origin or destination yet).

What can you do ?

  • Ask for the address of a place (eg: "what is the address of the Eiffel tour")
  • Ask for the distance / time between 2 places. (how far is "address A" from "Address B")
  • Ask for the directions between 2 places, on top of distance/time. (how to go from "Address A" to "Address B")

The synapse has a lot of options, so you can set your transportation mode (driving, walking, tube, …), the language, the units system, … Read the readme file as it contains more information (and more up to date).

Installation

Neuron

Usual neuron installation:

.. code:: bash

kalliope install --git-url https://github.com/bacardi55/kalliope-gmaps.git

Will install the neuron and the [google maps services python library)[https://googlemaps.github.io/google-maps-services-python/docs/2.4.5/)

Synapse

Get the distance and time between 2 locations

.. code:: yaml

  - name: "Gmaps-distance"
    signals:
      - order: "distance between {{origin}} and {{destination}}"
    neurons:
      - gmaps:
          gmaps_api_key: "*********"
          mode: "driving"
          language: "en"
          units: "metric"
          traffic_model: "pessimistic"
          args:
            - origin
            - destination
          file_template: "templates/en_gmaps.j2"

Get the address of a place by its name

.. code:: yaml

  - name: "Gmaps-place-address"
    signals:
      - order: "get address of {{search}}"
    neurons:
      - gmaps:
          gmaps_api_key: "******************"
          language: "en"
          units: "metric"
          args:
            - search
          file_template: "templates/en_gmaps.j2"

You can find more up to date example on the github readme page

template

Here is a single template file to handle multiple use cases:

.. code:: jinja

{% raw %}
{% if status == "KO" %}
    Sorry, but the search didn't work, Sir
{% elif status == "OK" %}
    {% if search %}
        {% if origin %}
            Distance between {{ origin }} and {{ search }} is {{ distance }}.
            You need around {{time}} to go there
            {% if time_traffic %}
                You need to plan {{time_traffic}} with the current traffic
            {% endif %}
        {% else %}
            Address of {{search}} is {{destination}}
        {% endif %}
    {% elif destination %}
        Distance between {{oringi}} and {{destination}} is {{distance}}
        You need about {{ time }} to go there.
        {% if time_traffic %}
          Plan {{ time_traffic }} with current traffic.
        {% endif %}
    {% endif %}

    {% if directions %}
        To go to {{destination}}, you need
        {% for direction in directions %}
            {{ direction }}
        {% endfor %}
    {% endif %}

{% endif %}
{% endraw %}

Of course, you can simplify by splitting it into several templates depending on the arguments you send.

What's next

Obviously, the Gmaps API is so rich that the possibility for this neuron are limitless… But at least this first version let you do the basics…

What I have in mind for next updates:

  • multi origin / destination
  • Leverage more API from google maps

As always, ideas or pull requests are more than welcome!

Kalliope system status neuron

Introduction

Couple of days ago, I created a very simple neuron to retrieve some system data and have an idea of the system kalliope runs on. It was in the same idea of the poorsman loganalyser I talked about before.

In all honesty, most credits goes to this github repository I found that did almost all the job for me.

What does it do ?

So far, it returns the following variable that can then be used in a template or say_template:

  • running_since
  • os: OS name
  • os_version: Kernel version
  • system_name: Name of your host
  • system_nb_core: Number of core
  • cpu: % of CPU usage
  • memory: % of memory usage
  • disk: % of disk usage

Look at the readme for an up to date list :)

Installation

The usual:

.. code:: bash

kalliope install --git-url https://github.com/bacardi55/kalliope-system-status.git

Usage

Create a brain file like this:

.. code:: bash

  - name: "System-status"
    signals:
      - order: "Step into analysis mode, please"
    neurons:
      - system_status:
          say_template:
            - "I'm running on {{os}}, kernel {{os_version}}, with {{system_nb_cores}} cores.    C P U usage {{cpu}} %  memory usage {{memory}} %  disk usage {{disk}} %"
          cache: False

Or create a more complex template :)

I'll add more into this, but if you have idea, PR on github or comment on this post :)