Home Assistant: Difference between revisions

Hexa (talk | contribs)
HAOS in Virtualbox Screenshot
Hexa (talk | contribs)
Combine declarative and UI defined automations: Simplify section, add copy pastable example for UI, add scripts
Line 317: Line 317:
</syntaxHighlight>
</syntaxHighlight>


== Combine declarative and UI defined automations ==
== Automations, Scenes, and Scripts from the UI ==


You can also declaratively define your automations while still being able to define them in Home Assistant UI. Automations defined in UI are stored in <code>/var/lib/hass/automations.yaml</code>. If you are not planning on using UI defined automations, then you can define them under  <code>services.home-assistant.config.automation</code>, otherwise split them into <code>services.home-assistant.config."automation manual"</code> and <code>services.home-assistant.config."automation ui"</code>, like so:
These can be created from the user interface, but the files generated from it need to be included in your configuration.<syntaxhighlight lang="nixos">
<syntaxHighlight lang=nix>
{
   services.home-assistant.config =
   services.home-assistant.config = {
  {
     "automation ui" = "!include automation.yaml";
     "automation manual" = [
    "scenes ui" = "!include scenes.yaml";
      {
     "scripts ui" = "!include scripts.yaml";
        alias = "living room plug off";
  };
        trigger = {
};
          platform = "time";
</syntaxhighlight>It is also possible to mix declarative and generated configuration for these components, by creating multiple configuration sections with the automation, scenes, or scripts prefix:
          at = "22:00";
        };
        action = {
          type = "turn_off";
          device_id = "someID"; #Inspect yaml of automation created in UI
          entity_id = "switch.living_room_plug";
          domain = "switch";
        };
      }
    ];
     "automation ui" = "!include automations.yaml";
}
</syntaxHighlight>
 
== Combine declarative and UI defined scenes ==
Same as with automations, scenes can also be configured both declaratively and from within the UI:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
services.home-assistant.config."scene manual" = [
services.home-assistant.config = {
  # declarative scenes go here
  "automation nixos" = [
];
    # YAML automations go here
services.home-assistant.config."scene ui" = "!include scenes.yaml";
  ];
  "automation ui" = "!include automations.yaml";
}
</syntaxhighlight>
</syntaxhighlight>