Simple Grammar Language (HGL) to reduce some reptitiveness

Not sure if it’s general enough to be of use to others, but I built a little grammar-based language for specifying parts of my YAML configuration. The below github repository contains my tool – – which converts from a file containing “Hass Grammar Language” (HGL) into the YAML that homeassistant understands natively. This allows me to write various concise automation rules in a more concise and natural way. E.g.,

when {pantry,kitchen}_ir is Normal for 3 minutes do turn_off(light.mh_m_*)

It also makes for easier mapping of MQTT messages to actions:

when EH_media_{pause,play,play_pause,volume_up,volume_down,channel_down} do media_player.media_*(entry_hall)

and paired behaviors keyed off of the time of day:

sunrise ... solar_noon -01:00:00
  with cover.mh_m_great_room_upper_east
    start when sunny:

The script is here:

YMMV: I’m not trying to replace YAML and believe that YAML is a great choice for what Home Assistant is trying to do – I’m just trying to capture some highly repetitive patterns on my YAML because of the volume of devices I have and the automations needed to support them.