From 5d2afdd825be5db78072a9b36d7d768f3a118470 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sun, 14 Mar 2021 07:03:50 -0700 Subject: [PATCH] Add motion light trace (#8637) --- gallery/src/data/traces/motion-light-trace.ts | 246 ++++++++++++++++++ gallery/src/demos/demo-automation-trace.ts | 5 +- src/data/automation.ts | 10 + src/data/automation_debug.ts | 2 +- 4 files changed, 260 insertions(+), 3 deletions(-) create mode 100644 gallery/src/data/traces/motion-light-trace.ts diff --git a/gallery/src/data/traces/motion-light-trace.ts b/gallery/src/data/traces/motion-light-trace.ts new file mode 100644 index 0000000000..353912a04c --- /dev/null +++ b/gallery/src/data/traces/motion-light-trace.ts @@ -0,0 +1,246 @@ +import { DemoTrace } from "./types"; + +export const motionLightTrace: DemoTrace = { + trace: { + last_action: "action/3", + last_condition: null, + run_id: "1", + state: "stopped", + timestamp: { + start: "2021-03-14T06:07:01.768006+00:00", + finish: "2021-03-14T06:07:53.287525+00:00", + }, + trigger: "state of binary_sensor.pauluss_macbook_pro_camera_in_use", + unique_id: "1614732497392", + action_trace: { + "action/0": [ + { + timestamp: "2021-03-14T06:07:01.771038+00:00", + changed_variables: { + trigger: { + platform: "state", + entity_id: "binary_sensor.pauluss_macbook_pro_camera_in_use", + from_state: { + entity_id: "binary_sensor.pauluss_macbook_pro_camera_in_use", + state: "off", + attributes: { + friendly_name: "Paulus’s MacBook Pro Camera In Use", + icon: "mdi:camera-off", + }, + last_changed: "2021-03-14T06:06:29.235325+00:00", + last_updated: "2021-03-14T06:06:29.235325+00:00", + context: { + id: "ad4864c5ce957c38a07b50378eeb245d", + parent_id: null, + user_id: null, + }, + }, + to_state: { + entity_id: "binary_sensor.pauluss_macbook_pro_camera_in_use", + state: "on", + attributes: { + friendly_name: "Paulus’s MacBook Pro Camera In Use", + icon: "mdi:camera", + }, + last_changed: "2021-03-14T06:07:01.762009+00:00", + last_updated: "2021-03-14T06:07:01.762009+00:00", + context: { + id: "e22ddfd5f11dc4aad9a52fc10dab613b", + parent_id: null, + user_id: null, + }, + }, + for: null, + attribute: null, + description: + "state of binary_sensor.pauluss_macbook_pro_camera_in_use", + }, + context: { + id: "43b6ee9293a551c5cc14e8eb60af54ba", + parent_id: "e22ddfd5f11dc4aad9a52fc10dab613b", + user_id: null, + }, + }, + }, + ], + "action/1": [ + { + timestamp: "2021-03-14T06:07:01.875316+00:00", + }, + ], + "action/2": [ + { + timestamp: "2021-03-14T06:07:53.195013+00:00", + changed_variables: { + wait: { + remaining: null, + trigger: { + platform: "state", + entity_id: "binary_sensor.pauluss_macbook_pro_camera_in_use", + from_state: { + entity_id: "binary_sensor.pauluss_macbook_pro_camera_in_use", + state: "on", + attributes: { + friendly_name: "Paulus’s MacBook Pro Camera In Use", + icon: "mdi:camera", + }, + last_changed: "2021-03-14T06:07:01.762009+00:00", + last_updated: "2021-03-14T06:07:01.762009+00:00", + context: { + id: "e22ddfd5f11dc4aad9a52fc10dab613b", + parent_id: null, + user_id: null, + }, + }, + to_state: { + entity_id: "binary_sensor.pauluss_macbook_pro_camera_in_use", + state: "off", + attributes: { + friendly_name: "Paulus’s MacBook Pro Camera In Use", + icon: "mdi:camera-off", + }, + last_changed: "2021-03-14T06:07:53.186755+00:00", + last_updated: "2021-03-14T06:07:53.186755+00:00", + context: { + id: "b2308cc91d509ea8e0c623331ab178d6", + parent_id: null, + user_id: null, + }, + }, + for: null, + attribute: null, + description: + "state of binary_sensor.pauluss_macbook_pro_camera_in_use", + }, + }, + }, + }, + ], + "action/3": [ + { + timestamp: "2021-03-14T06:07:53.196014+00:00", + }, + ], + }, + condition_trace: {}, + config: { + mode: "restart", + max_exceeded: "silent", + trigger: [ + { + platform: "state", + entity_id: "binary_sensor.pauluss_macbook_pro_camera_in_use", + from: "off", + to: "on", + }, + ], + action: [ + { + service: "light.turn_on", + target: { + entity_id: "light.elgato_key_light_air", + }, + }, + { + wait_for_trigger: [ + { + platform: "state", + entity_id: "binary_sensor.pauluss_macbook_pro_camera_in_use", + from: "on", + to: "off", + }, + ], + }, + { + delay: 0, + }, + { + service: "light.turn_off", + target: { + entity_id: "light.elgato_key_light_air", + }, + }, + ], + id: "1614732497392", + alias: "Auto Elgato", + description: "", + }, + context: { + id: "43b6ee9293a551c5cc14e8eb60af54ba", + parent_id: "e22ddfd5f11dc4aad9a52fc10dab613b", + user_id: null, + }, + variables: { + trigger: { + platform: "state", + entity_id: "binary_sensor.pauluss_macbook_pro_camera_in_use", + from_state: { + entity_id: "binary_sensor.pauluss_macbook_pro_camera_in_use", + state: "off", + attributes: { + friendly_name: "Paulus’s MacBook Pro Camera In Use", + icon: "mdi:camera-off", + }, + last_changed: "2021-03-14T06:06:29.235325+00:00", + last_updated: "2021-03-14T06:06:29.235325+00:00", + context: { + id: "ad4864c5ce957c38a07b50378eeb245d", + parent_id: null, + user_id: null, + }, + }, + to_state: { + entity_id: "binary_sensor.pauluss_macbook_pro_camera_in_use", + state: "on", + attributes: { + friendly_name: "Paulus’s MacBook Pro Camera In Use", + icon: "mdi:camera", + }, + last_changed: "2021-03-14T06:07:01.762009+00:00", + last_updated: "2021-03-14T06:07:01.762009+00:00", + context: { + id: "e22ddfd5f11dc4aad9a52fc10dab613b", + parent_id: null, + user_id: null, + }, + }, + for: null, + attribute: null, + description: "state of binary_sensor.pauluss_macbook_pro_camera_in_use", + }, + }, + }, + logbookEntries: [ + { + name: "Auto Elgato", + message: + "has been triggered by state of binary_sensor.pauluss_macbook_pro_camera_in_use", + source: "state of binary_sensor.pauluss_macbook_pro_camera_in_use", + entity_id: "automation.auto_elgato", + when: "2021-03-14T06:07:01.768492+00:00", + domain: "automation", + }, + { + when: "2021-03-14T06:07:01.872187+00:00", + name: "Elgato Key Light Air", + state: "on", + entity_id: "light.elgato_key_light_air", + context_entity_id: "automation.auto_elgato", + context_entity_id_name: "Auto Elgato", + context_event_type: "automation_triggered", + context_domain: "automation", + context_name: "Auto Elgato", + }, + { + when: "2021-03-14T06:07:53.284505+00:00", + name: "Elgato Key Light Air", + state: "off", + entity_id: "light.elgato_key_light_air", + context_entity_id: "automation.auto_elgato", + context_entity_id_name: "Auto Elgato", + context_event_type: "automation_triggered", + context_domain: "automation", + context_name: "Auto Elgato", + }, + ], +}; diff --git a/gallery/src/demos/demo-automation-trace.ts b/gallery/src/demos/demo-automation-trace.ts index c7bca8f523..ab8d3b6388 100644 --- a/gallery/src/demos/demo-automation-trace.ts +++ b/gallery/src/demos/demo-automation-trace.ts @@ -10,10 +10,11 @@ import "../../../src/components/ha-card"; import "../../../src/components/trace/hat-trace"; import { provideHass } from "../../../src/fake_data/provide_hass"; import { HomeAssistant } from "../../../src/types"; -import { basicTrace } from "../data/traces/basic_trace"; import { DemoTrace } from "../data/traces/types"; +import { basicTrace } from "../data/traces/basic_trace"; +import { motionLightTrace } from "../data/traces/motion-light-trace"; -const traces: DemoTrace[] = [basicTrace]; +const traces: DemoTrace[] = [basicTrace, motionLightTrace]; @customElement("demo-automation-trace") export class DemoAutomationTrace extends LitElement { diff --git a/src/data/automation.ts b/src/data/automation.ts index 2310f86610..b3a8679103 100644 --- a/src/data/automation.ts +++ b/src/data/automation.ts @@ -28,6 +28,16 @@ export interface ManualAutomationConfig { action: Action[]; mode?: typeof MODES[number]; max?: number; + max_exceeded?: + | "silent" + | "critical" + | "fatal" + | "error" + | "warning" + | "warn" + | "info" + | "debug" + | "notset"; } export interface BlueprintAutomationConfig extends ManualAutomationConfig { diff --git a/src/data/automation_debug.ts b/src/data/automation_debug.ts index 21a2cb0109..075a1d1a03 100644 --- a/src/data/automation_debug.ts +++ b/src/data/automation_debug.ts @@ -11,7 +11,7 @@ interface TraceVariables extends Record { interface BaseTrace { timestamp: string; - changed_variables: Record; + changed_variables?: Record; } export interface ConditionTrace extends BaseTrace {