Create a global variable with automation or something like alarm=on

Hi all,

I’m searching but I don’t know if it is possible to create a variable like “alarmstate” and change status to 1 or to 0 with an automation. I just switched from mi home to home assistant and I don’t find that.
I’m trying to configure home assistant as a alarm but I don’t know how to initialize this variable or use any other var that I can use when performing automations like… switch off camera if alarm is off but not on or switch on a light at 9:00pm if alarm is on.

I have some automations with if else (using time) but I need something to enable or disable when I turn alarm on or off and to use to perform some automations.

Thanks a lot to everyone.

In Home Assistant these are called Helpers… there are different types for different types of data; text, numbers, selects, etc. Toggles like you are looking for are called Input booleans. There are specific actions such as input_boolean.turn_on, input_boolean.turn_off, and input_boolean.toggle which are specifically designed to be used with them.

1 Like

Create a Trigger-based Template Sensor.

template:
 - trigger:
     - platform: event
       event_type: set_alarm_state
   sensor:
     - name: Alarm State
       state: "{{ trigger.event.data.state }}"

In your automation’s action use an Event service call like the following which sets the state of sensor.alarm_state to 1 (replace with 0 to set the sensor’s state to that value).

action:
  - event: set_alarm_state
    event_data:
      state: 1

Reference: WTH can't input helpers be read only in UI - #7 by CentralCommand

Or use an Input Boolean like Didgeridrew suggested. Main difference is that a Template Sensor is displayed as a read-only entity in the UI (your sensor will show 1 or 0) whereas an Input Boolean is displayed as a switch that the user can turn on/off.

1 Like