Virtual switch - input boolean

Hi,

I have a question about “virtual switches”

What do I have:

  1. Humidity sensor
  2. Relay switch

I have 2 simple automations.

This automation is used to turn on the relay if humidity is above 30%

alias: FilaDry 2 Control ON
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.filadry_2_humidity
    above: '30'
condition: []
action:
  - type: turn_on
    device_id: 16875d49db7511422192f1a6ded1abee
    entity_id: switch.filadry_2_relay
    domain: switch
mode: single

This automation is to turn off the relay if the humidity is below 20% for at least 10 minutes.

alias: FilaDry 2 Control OFF
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.filadry_2_humidity
    below: '20'
    for: '00:10:00'
condition: []
action:
  - type: turn_off
    device_id: 16875d49db7511422192f1a6ded1abee
    entity_id: switch.filadry_2_relay
    domain: switch
mode: single

This works fine…

Now I want to add a virtual switch on the same card where the main relay switch is and the humidity readout.
This switch controlls the first automation, if on, automation is active, if off automation will be ignored/off.

I have created a virtual switch:

input_boolean:
# Example configuration.yaml entry
  filadry_2_automation:
    name: "FilaDry 2 Automation"
    icon: mdi:home-automation

For this boolean I have added a switch function on my Card.

in my Turn On automation I have added this condition:

alias: FilaDry 2 Control ON
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.filadry_2_humidity
    above: '30'
condition:
  - condition: template
    value_template: '{{ is_state(''input_boolean.filadry_2_automation'', ''on'') }}'
action:
  - type: turn_on
    device_id: 16875d49db7511422192f1a6ded1abee
    entity_id: switch.filadry_2_relay
    domain: switch
mode: single

Now my Turn on automation will not activate, whatever the card switch is set to on or off.

What am i missing here?

Seems like your ‘virtual switch’ is just added complication - just add the automation to the dashboard, it will appear with a toggle switch to turn it on and off.

2 Likes

Same thought here, code below should do the trick.

    cards:
      - type: entities
        entities:
          - entity: automation.<id of automation>

image

2 Likes

You guys are awesome :smiley:
Works like a charm! Thanks!

1 Like

Maybe you guys can help me with expanding the first automation where the condition has to be for al least 10 minutes.

I want to add a timer in my card that counts down from the point the condition is starting at counting for 10minutes and show this in my card.

The only way to do that would be with a timer, but to be perfectly honest it’s pretty pointless and you’ll spend ages coding it to get it working and then in a couple of months you’ll realise that you don’t spend your whole day looking at the dashboard so the timer is pointless and remove it anyway.

The process with homeassistant is always the same.

  • Start doing cool automations
  • Design an amazing dashboard with a load of super-cool things on it to show off to your friends
  • Start refining your automations so that you hardly ever need to look at your dashboard because your home is smart and ‘just works’
  • Reduce your dashboard to a minimalist functional affair

I don’t want to stifle your journey through that process, but having a visual timer for this purpose is about 40 lines of code that doesn’t achieve anything.

And that’s exactly the difference, I mainly only use it to automate my production, instead of using it to automate my home. I don’t need that.

I just need to have good overviews of what is happening in certain processes, and it is nice to have a good interim read-out every now and then.

If possible, I will make it.

:wink:

Very well - in that case, instead if a simple automation that triggers after 10 minutes you’re going to need…

  • A timer configured
  • Your first automation to start the timer.
  • Another automation to monitor whether the timer needs to be stopped and reset and/or restarted (ie - if the temperature goes back up).
  • Another automation to fire when the timer reaches zero, to do what your original automation did

And even then, I have a feeling that lovelace might not represent it properly if the timer gets stopped and restarted (ie - the temperature spikes up and immediately back down), so you might have to add an extra step to the middle automation, but that might be overkill, will have to see what happens)

Anyway, good luck with it :slight_smile:

13 month later I don’t knkw what you decide buy maybe a graph or a journal would have done the job done in a simple manner and/or adding a “last change” info to your switch

玩技術也可以這樣寫

condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.example_switch
        state: "on"