@@ -4,6 +4,7 @@ let
44 configDir = "/var/lib/foobar";
55 apiPassword = "some_secret";
66 mqttPassword = "another_secret";
7+ hassCli = "hass-cli --server http://hass:8123 --password '${apiPassword}'";
78
89in {
910 name = "home-assistant";
@@ -16,7 +17,7 @@ in {
1617 { pkgs, ... }:
1718 {
1819 environment.systemPackages = with pkgs; [
19− mosquitto
20+ mosquitto home-assistant-cli
2021 ];
2122 services.home-assistant = {
2223 inherit configDir;
@@ -71,6 +72,11 @@ in {
7172 $hass->waitUntilSucceeds("mosquitto_pub -V mqttv311 -t home-assistant/test -u homeassistant -P '${mqttPassword}' -m let_there_be_light");
7273 $hass->succeed("curl http://localhost:8123/api/states/binary_sensor.mqtt_binary_sensor -H 'x-ha-access: ${apiPassword}' | grep -qF '\"state\": \"on\"'");
7374
75+ # Toggle a binary sensor using hass-cli
76+ $hass->succeed("${hassCli} entity get binary_sensor.mqtt_binary_sensor | grep -qF '\"state\": \"on\"'");
77+ $hass->succeed("${hassCli} entity edit binary_sensor.mqtt_binary_sensor --json='{\"state\": \"off\"}'");
78+ $hass->succeed("curl http://localhost:8123/api/states/binary_sensor.mqtt_binary_sensor -H 'x-ha-access: ${apiPassword}' | grep -qF '\"state\": \"off\"'");
79+
7480 # Print log to ease debugging
7581 my $log = $hass->succeed("cat ${configDir}/home-assistant.log");
7682 print "\n### home-assistant.log ###\n";