Conditional card problem

Hi, I’m trying to show a picture if an automation is on. I have managed with an entity card, to show current attribute of an automation, let’s say 0 to off, and 1 when on.
But if I use the condition card, and put that the automation entity is equal or not equal to on, off, 0, 1, there is no way to make it happen…where is the mistake?

By the way, if you ask me why I’m doing this: I want a button to open my building door, and, 30 seg later, open my apartment door. But, in case I accidentally click the button, I have 30 sg to stop the automation, to avoid my door is open when I’m out, and, I’d like to show a picture as a warning that my door will open in a short time.

The state of an automation (on/off) determines if the the automation is enabled or disabled, not if it is running or not. That is determined by an automation’s current attribute being > 0 (which you can’t use in a conditional card - look at state-swtich if this really what you want.

The building door always opens right away when you click the button?

I would do something like this.

  • Button Click opens building and start 30 second timer
  • Conditional card shows picture/button when timer is not idle
  • Picture/button cancels the timer when clicked
  • Apartment door open is triggered by timer finishing

If the timer is cancelled by the picture/button it never finishes and the apartment door won’t open.

1 Like

Hi again. I installed state-switch, adding js file, but no way to make it work, here the screenshot:

And the nice solution you provide me, idle is not working:

If you’re using the timer solution (recommended) you don’t need the state-switch.

You want to show the card when the timer state is NOT equal to idle, which means it is running (or paused). It should be working the way you have it, but backwards (showing when timer not on and invisible when it is).

If you have any more questions can you post the code instead of screen shots? Much easier to read to help you!

1 Like

Thanks a lot @jazzyisj, I really appreciate. Ok, this is my code, but nothing changes when automation is working or not, and I cannot understand why :thinking:

type: conditional
conditions:

Another idea: I have a card that tells me 0 or 1 if automation is idle or active, is this:

type: entity
entity: automation.test_timer
state_color: true
icon: mdi:door
attribute: current
name: testing timer

Is there any way to “parse” this 0 or 1 to a conditional card?

You don’t want to test the automation state for the condition. You want to test the timer state.

Did you create a timer yet? What is the timer entity id?
Does your automation start that timer?
The tap_action for your picture should cancel the timer

tap_action:
  action: call-service
  service: timer.cancel
  service_data:
    entity_id: timer.whatever_you_called_your_timer

One last request for you! Highlight any code you post in the forums and format it by clicking this button in the comment editor. Go back and edit your last message to try it out to see the difference it makes!

image

1 Like

Ok, in fact is not a timer, but a delay, probably this is not the way to do it. I copy my automation code:

- id: '16xxxxxxxx5683'
  alias: test_timer
  description: ''
  trigger: []
  condition: []
  action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
  - type: turn_on
    device_id: 6xxxxxxxxxx2
    entity_id: light.xxxxx
    domain: light
  mode: single

And thank you for the patience, I’m still learning, no screenshots and code in place :grin:

Ah ha. No you don’t want a delay. You want a timer.

Any BTW, you don’t have to sensor your entity_id, device_id. Nobody can do anything with that information but help you!

A timer is a helper. To create one go to the Settings Tab → Devices & Services → Helpers (at the top) or go here Link to Helpers – My Home Assistant. Click Add Helper on the bottom right and select Timer in the window that opens. The timer setup should be pretty self explanatory from there.

Now in your first automation that you will trigger with the button press you want to start that timer as well as open the building door. This is when the picture should appear in your UI (when the timer starts).

The timer will run for whatever duration you specified in the setup. The timer can be cancelled by clicking the picture. If this happens than nothing else happens (your apartment won’t open).

Now you want a second automation that will trigger on the timer finished event for your timer. This second automation should open your apartment door. This automation will only run if you don’t cancel the timer by clicking the picture.

1 Like

I have one last suggestion for you! If you add a double_tap or hold_action to your picture you can add a timer.finish event, which forces the timer to finish immediately. That means you can open your apartment door right away by double tapping or hold tapping (long press) the picture instead of always waiting the 30 seconds if needed.

double_tap_action:
  action: call-service
  service: timer.finish
  service_data:
    entity_id: timer.whatever_you_called_your_timer
1 Like

I still haven’t found my problem, not working.

I have this card:

show_name: true
show_icon: true
type: button
tap_action:
  action: call-service
  service: automation.trigger
  service_data: {}
  target:
    entity_id: automation.openhouse
entity: automation.openhouse

that trigger this automation:

- id: '1652889765683'
  alias: openhouse
  description: ''
  trigger: []
  condition: []
  action:
  - type: turn_on
    device_id: e6xxxxx709
    entity_id: switch.sonoff_10007a20b2
    domain: switch
  - service: timer.start
    data: {}
    target:
      entity_id: timer.upstairs
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - service: script.opendoorappartment
    data: {}
  mode: single

And this conditional:

type: conditional
conditions:
  - entity: timer.upstairs
    state_not: idle
card:
  type: picture
  image: /local/lladre.webp
  tap_action:
    action: call-service
    service: timer.finish
    service_data: {}
    target:
      entity_id: timer.upstairs
  hold_action:
    action: none

The odd thing: when I click the picture, timer stops, BUT, after 30 sg, door2 opens, it looks like stoping the timer does not stop automation…

You’re almost there!

If you go back and reread my previous reply, I explained that you need to split the automation up. You didn’t do that. You have nothing there that will stop the automation if the timer is cancelled. You also left that delay in, which you don’t need.

You can actually do this in one automation. I just didn’t want to confuse you with additional elements. Anyway, I put it together here for you here. Have a good look so you understand what is happening.

The other change I would make is you just created a button card, not a button helper. Although the way you did this it will technically work it’s not the best practice.

In the same place you created your timer (Helpers Page) you should create a button helper. I would do that first. If you name that button “Open House” this code should work without changes.

  • Pressing the new button helper you just created triggers the automation
  • The switch turns on (I assume for building door)
  • Timer starts (I assume 30 seconds - if not change the wait_for_trigger timeout to match)
  • The automation now waits for the timer to finish.
  • If the timer does not finish (because you cancelled it) the automation stops here (continue_on_timeout: false)
  • When the timer finishes the automation continues and runs your apartment door script.

You should be able to copy this and paste this into the automation YAML editor exactly the way it is. Make sure you delete everything else in the editor before pasting.

  alias: openhouse
  description: ''
  trigger:
    - platform: event
      event_type: button.press
      event_data:
        entity_id: button.open_house
  condition: []
  action:
    - service: switch.turn_on
      target:
        entity_id: switch.sonoff_10007a20b2
    - service: timer.start
      data: {}
      target:
        entity_id: timer.upstairs
    - wait_for_trigger:
        - platform: event
          event_type: timer.finished
          event_data:
            entity_id: timer.upstairs
      timeout: 30
      continue_on_timeout: false
    - service: script.opendoorappartment
  mode: restart

BTW if you want to simplify, you can get rid of the button card and replace it with just the button entity in an entities card. I’m showing you this so you understand the difference between a button entity and a button card. Try adding both to your lovelace view so you can see the difference, then delete the one you don’t want (probably the entities card).

Option 1 - Entities Card

- type: entities
  entities:
    - entity: button.open_house

Option 2 - Button Card
I also added in the double tap to run the openappartment script immediately without waiting for the timer to finish also since I have the entity_id now.

  - type: button
    entity: button.open_house
    tap_action:
      action: call-service
      service: button.press
      service_data:
        entity_id: button.open_house
    double_tap_action:
      action: call-service
      service: script.opendoorappartment

When you get all this working, get back to me. There is one change you should really make to script.opendoorappartment to make sure the apartment door doesn’t try to open twice. I’ll help you do that once you’ve got this part working.

1 Like

Thank you Jason @jazzyisj, very much, I really appreciate. Finally, after watching a lot of videos about automation, now I get it, thanks thanks thanks, you are an amazing teacher!!! Even the script, I can do it by myself. I don’t know if I’m taking advantage of you talking about another problem that I have, weeks trying without success, is about connecting 2 HA with remote, should I open another topic? :grinning: :grinning: :grinning:

Happy to help.

Yes, you should start a new thread. It’s not something I’ve ever done, so I likely won’t be able to help you with that. Have you searched the forums for this issue yet? I know I’ve seen threads about running two instances of HA in the past.

I am curious why you need to run 2 connected instances of HA though. It is a pretty advanced thing to do, and normally not required.