joBr99 / nspanel-lovelace-ui

Custom Firmware for NsPanel with the design of HomeAssistant's lovelace UI in mind, works with Tasmota.
GNU General Public License v3.0
854 stars 187 forks source link

Fixed typing #1186

Closed Odianosen25 closed 4 months ago

Odianosen25 commented 4 months ago

This fixes a typing with the current card access, and as requested an example of how it can be used

The use case is as outlined:

By default the buttons are used to switch off lights assigned to them, when clicked once (single) When they are double pressed (double), its used to instruct to switch off the whole room This will then show a hidden card, requesting to confirm switch off Buttons are used on the card to confirm or reject, but at the same time the physical buttons can be used

First a hidden card is created, to display the message to confirm switch off

   hiddenCards:
      - type: cardGrid
        title: Confirm Off
        key: confirm_living_room_off
        entities:
          - entity: input_button.living_room_turn_off_accept
            name: Accept
            icon: mdi:check
          - entity: delete
          - entity: input_button.living_room_turn_off_reject
            name: Reject
            icon: mdi:close

An AD app is written to decide of its a single button event, it will switch on/off the light. But if double, it will show the confirm page. When the confirm page is being shown, the buttons will be used to either confirm/reject the request.


   def button_event(self, event: str, data: dict, kwargs: dict) -> None:
        """Button event triggered"""

        area_id = kwargs["area_id"]
        action = data["action"]

        if action == "single":
            # we get the app first
            panel_app = self.adapi.get_app(f"{area_id}_nspanel")
            ns_card = panel_app.current_card
            if ns_card == f"confirm_{area_id}_off":
                # its for confirmation switch off
                button = data["button"]
                if button == "button1":
                    self.hass.call_service("input_button/press", entity_id=f"input_button.{area_id}_turn_off_accept")

                elif button == "button2":
                    self.hass.call_service("input_button/press", entity_id=f"input_button.{area_id}_turn_off_reject")

            else:
                # its for single control of devices
                zigbee_entity = kwargs["zigbee_entity"]
                self.z2m.toggle(zigbee_entity)

        elif action == "double":
            # its for the other controls
            payload = json.dumps({"CustomRecv":f"event,buttonPress2,navigate.confirm_{area_id}_off,button"})
            self.mqtt.mqtt_publish(f"tele/{area_id}_wall_panel/RESULT", payload=payload)

image

joBr99 commented 4 months ago

thanks, will try to document this on a page in die documentation soon (https://github.com/joBr99/nspanel-lovelace-ui/tree/main/docs)

Btw: If you have an esp32 developer board laying around you can emulate a panel in the nextion editor aswell. (the iobroker guys documented my loose notes on that quite well, even though it's in german ;) https://github.com/joBr99/nspanel-lovelace-ui/wiki/NSPanel-Nextion-Editor

Odianosen25 commented 4 months ago

Unfortunately I do not have any board.

Though one thing I would have loved to do, is to use AD based entities or entities outside the HASS namespace.

That way I can use their state changes, and define custom service parameters for button presses than just HA's.

I am not sure where to tackle it from though, could do with pointers if you can.

Kind regards