Message when turn on switch

Hi all, I’m trying to create a entity card for my garagedoor motor. And i would like a message to popup like, are you sure you want to open the garagedoor ?
I have magnetic sensor, so based on the state the message should change between do you want to open or do you want to close.
Can someome point me in right direction how to solve this? thanks! I have created a template sensor that change depending on the magnetic sensors.

garage_door_message: friendly_name: garage_door_message value_template: >- {% if ( (is_state(‘sensor.garage_magnet_open’,‘1’)) and (is_state(‘sensor.garage_magnet_closed’,‘0’)) ) %}
Do you want to close?
{% elif ( (is_state(‘sensor.garage_magnet_open’,‘0’)) and (is_state(‘sensor.garage_magnet_closed’,‘1’)) ) %}
Do you want to open? {% endif %}

What is the trigger (switch) to open or close the garage door with the motor? Is it a entity controlled in HA?

Yes, exactly. I have a shelly 1 that is connected to the garagedoor motor.

type: entities
entities:
  - type: section
    label: Back Tank
  - type: buttons
    entities:
      - entity: switch.water_tank_back_pump
        name: Pump
        tap_action:
          action: toggle
          confirmation:
            text: Are you sure you want to turn the Pump on/off?
        hold_action:
          action: more-info

You have to use a button to get the confirmation option in an entities card (without using something custom).

Great :slight_smile: but is there someway to change the text depending on a sensor value?

Oké,

Where you want to send the message to? I think you want to decide via the notification if you want to open or close?

You can use Actionable Notifications

You have to create a dummy switch (Open/Close) and build automations based on the state of the dummy switch, to sent a notification to your end-device.

I guess you could probably create a conditional entity to ‘show’ a different entity (but actually the same one, just with a different confirmation message). I never bothered with this though.

I just want a confirmation window with “yes/no” on the device where i tap the switch, could be my phone, tablet or computer.
But the message should change from “do you want to close the door” to “do you want to open the door”

I fixed it with a custom button card, here is my code if someone needs it.
The messages is in Swedish :slight_smile:

The icon is red when the garagedoor is closed
Blinking yellow when it’s opening
And green when it’s opened.

type: custom:button-card
show_name: false
entity: sensor.garage_door_status
show_state: true
size: 20%
secondary_info: last-changed
tap_action:
entity: switch.shelly1pm_84cca8ad2d7d
action: toggle
confirmation:
text: |
[[[
if (states[“sensor.garage_magnet_open”].state == ‘1’)
return “Är du säker på att du vill stänga garageporten?”;
if (states[“sensor.garage_magnet_closed”].state == ‘1’)
return “Är du säker på att du vill öppna garageporten?”;
]]]
state:

  • value: Garageport stängd
    icon: mdi:garage-variant-lock
    styles:
    icon:
    - color: red
  • value: Garageport i mellanläge
    icon: mdi:garage-variant
    styles:
    icon:
    - color: orange
    - animation: blink 2s ease infinite
  • value: Garageport öppen
    icon: mdi:garage-open-variant
    styles:
    icon:
    - color: green
1 Like

Please post your code using the the community standards

Check out #11