Skip to content

Instantly share code, notes, and snippets.

@alexdelprete
Created March 11, 2023 22:41
Show Gist options
  • Save alexdelprete/a8d6ad98ae2c934f12606becd4b01b61 to your computer and use it in GitHub Desktop.
Save alexdelprete/a8d6ad98ae2c934f12606becd4b01b61 to your computer and use it in GitHub Desktop.
Nuki Hub Mushroom Card
type: custom:stack-in-card
cards:
- type: custom:mushroom-template-card
layout: horizontal
primary: >
{% set lock_name = state_attr('lock.portoncino','friendly_name') %} {% set
trigger = states('sensor.portoncino_trigger') %} {% if
is_state('lock.portoncino','unlocked') and
is_state('binary_sensor.portoncino_door_sensor','off') %}
{{ lock_name }}: closed & unlocked by {{ trigger }}
{% elif is_state('lock.portoncino','locked') and
is_state('binary_sensor.portoncino_door_sensor','off') %}
{{ lock_name }}: closed & locked by {{ trigger }}
{% elif is_state('lock.portoncino','unlocked') and
is_state('binary_sensor.portoncino_door_sensor','on') %}
{{ lock_name }}: open & unlocked by {{ trigger }}
{% else %}
{{ lock_name }}: state unknown!
{% endif %}
secondary: >
{% set battery_level = states('sensor.portoncino_battery_level') | int |
round(0) %} {% set bt_rssi_level =
states('sensor.portoncino_bluetooth_signal_strength') | int | round(0) %}
{% set wifi_rssi_level = states('sensor.portoncino_wifi_signal_strength')
| int | round(0) %} {% set uptime = states('sensor.portoncino_uptime') |
int %} Battery: {{ battery_level ~ '%' }} | BT: {{ bt_rssi_level ~ 'dBm'
}} | WiFi: {{ wifi_rssi_level ~ 'dBm' }} | Uptime: {{ uptime ~ 'm' if
(uptime|int) < 60 else ((uptime|int)/60)|round(1) ~ 'h' }}
icon: >
{% if is_state('lock.portoncino','unlocked') and
is_state('binary_sensor.portoncino_door_sensor','off') %}
mdi:door-closed
{% elif is_state('lock.portoncino','locked') and
is_state('binary_sensor.portoncino_door_sensor','off') %}
mdi:door-closed-lock
{% elif is_state('lock.portoncino','unlocked') and
is_state('binary_sensor.portoncino_door_sensor','on') %}
mdi:door-open
{% endif%}
icon_color: >
{% if is_state('lock.portoncino','locked') and
is_state('binary_sensor.portoncino_door_sensor','off') %}
green
{% elif is_state('lock.portoncino','unlocked') and
is_state('binary_sensor.portoncino_door_sensor','off') %}
yellow
{% elif is_state('lock.portoncino','unlocked') and
is_state('binary_sensor.portoncino_door_sensor','on') %} %}
red
{% endif%}
badge_icon: >
{% set battery_level = states('sensor.portoncino_battery_level') | int |
round(0) %} {% if battery_level < 80 %}
mdi:battery-{{ battery_level }}
{% elif battery_level < 60 %}
mdi:battery-alert-variant-outline
{% else %} {% endif %}
badge_color: >
{% set battery_level = states('sensor.portoncino_battery_level') | int |
round(0) %} {% if battery_level < 80 %}
orange
{% elif battery_level < 60 %}
red
{% else %}
green
{% endif %}
tap_action:
action: none
card_mod:
style: |
ha-card {
background: none;
box-shadow: none;
}
- type: custom:mushroom-lock-card
entity: lock.portoncino
name: Laundry Room Door
primary_info: none
secondary_info: none
icon_type: none
layout: vertical
card_mod:
style: |
ha-card {
background: none;
box-shadow: none;
}
@thor9898
Copy link

Thank you very much, brother
I appreciate your willingness to help me!
Now I only need for the Mushroom cards to give the option to have a confirmation message for unlatch

@alexdelprete
Copy link
Author

My pleasure brother. :)

@thor9898
Copy link

thor9898 commented Apr 2, 2023

Hi brother, lately i'm having an issue with this card, from time to time it says state unknown, are you getting the same error?

image

image
Just taking this last screenshot I realized that although the entity for the binary sensor's door still reports data, it isn't showing inside the mqtt device for the nuki hub, I don't know if this might be the problem.

@alexdelprete
Copy link
Author

alexdelprete commented Apr 2, 2023

My friend...I don't see your door sensor in the device page. Do you have one?

The template I gave you is based on the status of LOCK + DOOR SENSOR. If you don't have the Door Sensor, it should've never worked. :)

The overall status presented in the template is determined by this code: if lock is X AND door is Y then output that message.

      {% set lock_name = state_attr('lock.portoncino','friendly_name') %} {% set
      trigger = states('sensor.portoncino_trigger') %} {% if
      is_state('lock.portoncino','unlocked') and
      is_state('binary_sensor.portoncino_door_sensor','off') %}
        {{ lock_name }}: closed & unlocked by {{ trigger }}
      {% elif is_state('lock.portoncino','locked') and
      is_state('binary_sensor.portoncino_door_sensor','off') %}
        {{ lock_name }}: closed & locked by {{ trigger }}
      {% elif is_state('lock.portoncino','unlocked') and
      is_state('binary_sensor.portoncino_door_sensor','on') %}
        {{ lock_name }}: open & unlocked by {{ trigger }}
      {% else %}
        {{ lock_name }}: state unknown!
      {% endif %}

I suspect you're having issues with the door sensor, sometimes it needs to be reconfigured again via the Nuki Mobile app.

@thor9898
Copy link

thor9898 commented Apr 3, 2023

I understand the lines for the status as they are pretty straightforward, and as I was telling you I after taking the last screenshot I realized that the door sensor wasn't showing up in the mqtt nuki device, I don't know what update broke it. But the binary sensor is still reporting data and with the same entity ID
image

image

      {% if is_state('lock.nuki','unlocked') and
      is_state('binary_sensor.puerta_de_casa_door_sensor','off') %}
        mdi:door-closed
      {% elif is_state('lock.nuki','locked') and
      is_state('binary_sensor.puerta_de_casa_door_sensor','off') %}
        mdi:door-closed-lock
      {% elif is_state('lock.nuki','unlocked') and
      is_state('binary_sensor.puerta_de_casa_door_sensor','on') %}
        mdi:door-open
      {% endif%}

@alexdelprete
Copy link
Author

Who's creating that binary_sensor? Check in the entities to which integration it is linked.

image

If it's MQTT, then it's Nuki Hub. If it's another integration, you shouldn't be using it together with Nuki Hub.

@thor9898
Copy link

thor9898 commented Apr 5, 2023

It was saying mqtt although it wasn't being shown inside the Nuki hub device I don't know why.
But never mind. 8.21 update fixed it and it's showing inside the Nuki hub device again now. I haven't tested it much, but it's working well now so, I won't disturb you anymore 😅😅😅

image

Ps: Again, I appreciate your willingness to help and giving me support for this issue, it's nice to find kind-hearted people on the internet that helps with kind words even with the dumbest things. I currently live in Spain in a non-tourist city at all but will most likely move to London in the near future as I have family there if you ever there and want a beer or cyder just let me know and it will be on me for sure, my Mediterranean brother!! Thank you very much

@alexdelprete
Copy link
Author

Don't worry my friend, it's nothing special. If you need anything, you know how to contact me. I'm also on Discord (alexdelprete#5566) and Telegram (@alexdelprete). :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment