Remember this from the home assistant documentation?:
(trigger) When Paulus arrives home
(condition) and it is after sunset
(action) Turn the lights on in the living room
which you can rephrase this in Gherkin syntax as:
(condition) Given it is after sunset
(trigger) When Paulus arrives home
(action) Then turn the lights on in the living room
Gherkin is one of the tooling in Behavior Driven Development to start your development process with describing your features in scenarios. It defines this behavior in a human readable language so that both developers and non-technical stakeholders can understand and describe the features to deliver.
Also for developers it is good to first think about the scenario, without thinking in technical solutions and over time automatically building your documentation because it is part of your development process.
This is exactly the aim of this project, start with describing my automations in a human readable language and having them documented over time, apart from my yaml code.
Having a set of gherkin feature files, like below, is my starting point for creating and updating automations. first describe it in words, then start implementing it.
This (typescript) script will allow you to define and test your automations using the Gherkin language used in Behavior Driven Development (BDD).
You can find the latest code at github:
Sample gherkin file
Feature: Arriving and leaving home
Scenario: Arriving home after sunset
Given it is after sunset
When Paulus arrives home
Then turn the lights on in the living room
And switch on the television
implementation in YAML automation code:
########################################
# SCENARIO Arriving home after sunset
########################################
- alias: |-
Scenario arriving: Arriving home after sunset
id: scenario_arriving_arriving_home_after_sunset
# GIVEN
condition:
- alias: |-
Given it is after sunset
condition: "{{ is_state('sun.sun','below_horizon') }}"
# WHEN
trigger:
# When Paulus arrives home
- platform: state
entity_id: person.paulus
from: not_home
to: home
# THEN
action:
- alias: |-
Then turn the lights on in the living room
service: script.tafel_lights_off
- alias: |-
And switch on the television
service: switch.turn_on
target:
entity_id: switch.tv