Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement NSpanel notification via HA notify platform #2188

Closed
Kaibob2 opened this issue Jul 17, 2024 · 28 comments
Closed

Enhancement NSpanel notification via HA notify platform #2188

Kaibob2 opened this issue Jul 17, 2024 · 28 comments
Labels
Enhancement For suggestions that add new features or improve existing functionalities.

Comments

@Kaibob2
Copy link

Kaibob2 commented Jul 17, 2024

Enhancement Summary

If NSpanel would provide a notify.nspanel_xxx service, sending notifications would be easier.

Detailed Description

I'm still struggling getting alarmo to work properly on the NSpanel. The problem is the "weird" behaviour of the alarm page when there are sensors open which require to be closed to arm the alarm. In the HA dashboard an according message pops up indicating which sensor(s) "blocks" arming the alarm (when using the alarmo card). This is also discussed here #1088
I see, that a complete redesign of the alarm page would be a struggle, so I thought of another approach.
Alarmo supports sending notifications for each and every event natively.
https://github.com/nielsfaber/alarmo?tab=readme-ov-file#wildcards
I currently use this with the pushover integration, with great success.
Wouldn't it be possible to have a command available like notify.nspanel_livingroom which expects the default data for notifications?
I suppose in this project https://github.com/lubeda/EHMTX_custom_component/tree/main something very similar was done.

If you could simply call a notify service via alarmo to the nspanel as target when there is an open sensor a notifiaction would show up on the panel displaying which senor(s) are open.

Additional Context

No response

@Kaibob2 Kaibob2 added the Enhancement For suggestions that add new features or improve existing functionalities. label Jul 17, 2024
@overdrivesFR
Copy link

Currently facing the same issue.
I'm trying to pass on the open sensor name with a wildcard to the esphome notification service, but it only works with plain text.
Having some usual notify service would be perfect.

Also Kaibob2 I've never heard of Pushover before, I would be interested in seeing the way you use it (since we both want the exact same thing I'd basically only need to change the panel name)

@Kaibob2
Copy link
Author

Kaibob2 commented Oct 2, 2024

I'm currently in the process of completely rebuilding my complete home automation due to moving from an appartment to a house which is, sadly, currently a construction site :)
I'm widely using NodeRed for the more complex automations as there is a dedicated Pushover node available.
Pushover is a great notification service as it is 100% reliable, has an android app which never sleeps and supports actionable notifications. https://pushover.net/

I solved the "open sensors when arming issue" quick and dirty with the following in node red:

[
    {
        "id": "a3c0c4b3ae68dd70",
        "type": "api-call-service",
        "z": "79fbee1193f7f074",
        "name": "",
        "server": "d03fc0aa.7f6a18",
        "version": 5,
        "debugenabled": false,
        "domain": "esphome",
        "service": "ns_panel_wohnzimmer_notification_show",
        "areaId": [],
        "deviceId": [],
        "entityId": [],
        "data": "{\t      \"label\": \"Arming impossible\",\t  \"message\": \"There are open sensors.\"\t}",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 890,
        "y": 560,
        "wires": [
            []
        ]
    },
    {
        "id": "0c5895c2288f0909",
        "type": "trigger-state",
        "z": "79fbee1193f7f074",
        "name": "",
        "server": "d03fc0aa.7f6a18",
        "version": 4,
        "inputs": 0,
        "outputs": 2,
        "exposeAsEntityConfig": "",
        "entityId": "alarm_control_panel.alarmzentrale",
        "entityIdType": "exact",
        "debugEnabled": false,
        "constraints": [
            {
                "targetType": "this_entity",
                "targetValue": "",
                "propertyType": "property",
                "propertyValue": "data.new_state.attributes.open_sensors",
                "comparatorType": "is_not",
                "comparatorValueDatatype": "str",
                "comparatorValue": "null"
            }
        ],
        "customOutputs": [],
        "outputInitially": false,
        "stateType": "str",
        "enableInput": false,
        "x": 220,
        "y": 580,
        "wires": [
            [
                "40f4f691086c4eb6"
            ],
            []
        ]
    },
    {
        "id": "40f4f691086c4eb6",
        "type": "switch",
        "z": "79fbee1193f7f074",
        "name": "",
        "property": "data.event.new_state.attributes.open_sensors",
        "propertyType": "msg",
        "rules": [
            {
                "t": "nnull"
            },
            {
                "t": "null"
            },
            {
                "t": "eq",
                "v": "",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 3,
        "x": 570,
        "y": 600,
        "wires": [
            [
                "a3c0c4b3ae68dd70"
            ],
            [
                "da0fca1153dfc59b"
            ],
            []
        ]
    },
    {
        "id": "da0fca1153dfc59b",
        "type": "api-call-service",
        "z": "79fbee1193f7f074",
        "name": "",
        "server": "d03fc0aa.7f6a18",
        "version": 5,
        "debugenabled": false,
        "domain": "esphome",
        "service": "ns_panel_wohnzimmer_notification_clear",
        "areaId": [],
        "deviceId": [],
        "entityId": [],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 890,
        "y": 640,
        "wires": [
            []
        ]
    },
    {
        "id": "d03fc0aa.7f6a18",
        "type": "server",
        "name": "Home Assistant",
        "version": 5,
        "addon": true,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true,
        "heartbeat": false,
        "heartbeatInterval": "30",
        "areaSelector": "friendlyName",
        "deviceSelector": "friendlyName",
        "entitySelector": "friendlyName",
        "statusSeparator": "at: ",
        "statusYear": "hidden",
        "statusMonth": "short",
        "statusDay": "numeric",
        "statusHourCycle": "h23",
        "statusTimeFormat": "h:m",
        "enableGlobalContextStore": true
    }
]

grafik

Maybe when I will ever have some spare time again I'll try to have the sensors listed on the panel by their names. For the moment I'm fine with the information that there IS any open window or door.

@overdrivesFR
Copy link

My problem truly is the open sensor name. Simply showing a warning on the nspanel was easy.
Either creating a script and calling it upon activation fail in Alarmo action tab :

alias: test2 notifs
sequence:
  - data:
      label: Warning
      message: A sensor is open
    action: esphome.nspanel1_notification_show
mode: single
description: ""

Or you can simply call the service by editing the action yaml in Alarmo action tab :

- service: esphome.nspanel1_notification_show
  data:
    label: Warning
    message: A sensor is open

The second one being really easy, but fails to pass on the wildcards.

@edwardtfn
Copy link
Collaborator

Wouldn't it be possible to have a command available like notify.nspanel_livingroom which expects the default data for notifications?

Unfortunately ESPHome does not supports notify service, so the only way is using esphome services. 😩

The second one being really easy, but fails to pass on the wildcards.

Could you please detail it better?

@overdrivesFR
Copy link

overdrivesFR commented Oct 2, 2024

Could you please detail it better?

- service: esphome.nspanel1_notification_show
  data:
    label: Warning
    message: {{open_sensors|lang=fr}}

returns the error
value should be a string for dictionary value @ data['message']

And "tricking" it by using message: Text {{open_sensors|lang=fr}} sends the whole thing in plain text.

@edwardtfn
Copy link
Collaborator

What about this?

- service: esphome.nspanel1_notification_show
  data:
    label: Warning
    message: '{{open_sensors|lang=fr}}' 

@overdrivesFR
Copy link

First thing I tried, plain text as well.

@edwardtfn
Copy link
Collaborator

And what about this?

- service: esphome.nspanel1_notification_show
  data:
    label: Warning
    message: '{{ open_sensors }}' 

What is the content of open_sensors?

@edwardtfn
Copy link
Collaborator

I've just tried this and it worked just fine:

action: esphome.office_workstation_panel_notification_show
data:
  label: Test 01
  message: >
    Battery status unavailable: {{
      states.sensor
      | selectattr('attributes.device_class', 'defined')
      | selectattr('attributes.device_class', 'eq', 'battery')
      | rejectattr('state', 'is_number')
      | map(attribute="attributes.friendly_name")
      | list
      | join("/r")
    }}

@overdrivesFR
Copy link

What is the content of open_sensors?

{{ open_sensors }}, literally ^^

@edwardtfn
Copy link
Collaborator

But is it a list of entity_id's, or a string, or what?

@Kaibob2
Copy link
Author

Kaibob2 commented Oct 2, 2024

Looks like a list to me.

code_format: null
changed_by: null
code_arm_required: false
arm_mode: null
next_state: disarmed
open_sensors:
  binary_sensor.ble_opening_fenster_wz_rechts: open
  binary_sensor.ble_opening_fenster_wz_links: open
bypassed_sensors: null
delay: null
friendly_name: Alarmzentrale
supported_features: 47

@overdrivesFR
Copy link

overdrivesFR commented Oct 2, 2024

But is it a list of entity_id's, or a string, or what?

Oh my bad.
It's a string that shows the entity alias which prevents Alarmo from arming, and its state ("Garage door is open").

I can also use the wildcards using dev tools, the problem I'm facing is strictly from Alarmo.
But using them with the notify service to my smartphone works fine, so it's more of a "how to interact with the nspanel notification" thing than an alarmo problem per se.

@Kaibob2
Copy link
Author

Kaibob2 commented Oct 2, 2024

Aren't we talking about the attribute "open_sensors" from alarmo which gets populated when the alarm is armed. Meaning it switches from "null" to, for Example, what I posted above.

@Kaibob2
Copy link
Author

Kaibob2 commented Oct 2, 2024

Screenshot_20241002-230056

Screenshot_20241002-230352

@edwardtfn
Copy link
Collaborator

edwardtfn commented Oct 3, 2024

Looks like a list to me.

code_format: null
changed_by: null
code_arm_required: false
arm_mode: null
next_state: disarmed
open_sensors:
  binary_sensor.ble_opening_fenster_wz_rechts: open
  binary_sensor.ble_opening_fenster_wz_links: open
bypassed_sensors: null
delay: null
friendly_name: Alarmzentrale
supported_features: 47

It is a dictionary. Your panel's action requires a string, so you have to transform it.

Please try this:

- service: esphome.nspanel1_notification_show
  data:
    label: Warning
    message: '{{ open_sensors.keys() | list | join("\r") }}' 

Or this:

- service: esphome.nspanel1_notification_show
  data:
    label: Warning
    message: '{{ state_attr("alarm_control_panel.alarmzentrale", "open_sensors").keys() | list | join("\r") }}' 

@overdrivesFR
Copy link

That's really close, thanks.
The last problem I face is showing the friendly name instead of the sensor name.
If I use :
{{ state_attr(state_attr("alarm_control_panel.alarmo", "open_sensors").keys() | list | join("\r"), 'friendly_name') }}
It works in a template, it returns something like "Garage door", but not as the content of a message, home assistant reject the synthax and refuse to save it. (maybe there's something obvious here, but I'm barely starting using yaml)

@Kaibob2
Copy link
Author

Kaibob2 commented Oct 3, 2024

For me
{{ state_attr(state_attr("alarm_control_panel.alarmzentrale", "open_sensors").keys() | list | join("\r"), 'friendly_name') }}
gives
grafik
when more than one sensor is open.

@edwardtfn
Copy link
Collaborator

state_attr requires a single string with an entity_id, you are passing a list of strings.

Please try this:

- service: esphome.nspanel1_notification_show
  data:
    label: Warning
    message: 'The following sensors are open:\r{{ states.binary_sensor | selectattr("entity_id", "in", state_attr("alarm_control_panel.alarmzentrale", "open_sensors").keys() | list) | map(attribute="attributes.friendly_name") | list | join("\r") }}' 

@Kaibob2
Copy link
Author

Kaibob2 commented Oct 4, 2024

NICE!! Thanks a lot!!

{{ states.binary_sensor | selectattr("entity_id", "in", state_attr("alarm_control_panel.alarmzentrale", "open_sensors").keys() | list) | map(attribute="attributes.friendly_name") | list | join(", ") }}

grafik

@edwardtfn
Copy link
Collaborator

Nice!!

By the way, join(", ") will work fine on the template screen.
I've suggested join("\r") as that will include a line break on the Nextion screen...
It's up to you... 😉

@Kaibob2
Copy link
Author

Kaibob2 commented Oct 6, 2024

Sorry to reopen this, but when I insert this code in the Alarmo actions as "failed to arm" action

- service: esphome.ns_panel_wohnzimmer_notification_show
  data:
    label: Warning
    message: >-
      The following sensors are open:\r{{ states.binary_sensor |
      selectattr("entity_id", "in",
      state_attr("alarm_control_panel.alarmzentrale", "open_sensors").keys() |
      list) | map(attribute="attributes.friendly_name") | list | join("\r") }}

The label is displayed on the panel but the message stays empty.

WhatsApp Bild 2024-10-06 um 11 29 19_2883fb11

This is the ESPHOME log:

[11:27:29][D][resistance:039]: 'resistance_sensor' - Resistance 10219.9Ω
[11:27:29][D][sensor:094]: 'resistance_sensor': Sending state 10219.87793 Ω with 1 decimals of accuracy
[11:27:29][D][ntc:026]: 'Temperature' - Temperature: 24.5°C
[11:27:29][D][sensor:094]: 'Temperature': Sending state 24.51133 °C with 1 decimals of accuracy
[11:27:31][D][esp32_ble_tracker:270]: Starting scan...
[11:27:32][D][script:077]: Script 'timer_dim' restarting (mode: restart)
[11:27:32][D][script:077]: Script 'timer_sleep' restarting (mode: restart)
[11:27:32][D][text_sensor:064]: 'Notification Label': Sending state 'Warning'
[11:27:32][D][text_sensor:064]: 'Notification Text': Sending state 'The following sensors are open:\r{{ states.binary_sensor | selectattr("entity_id", "in", state_attr("alarm_control_panel.alarmzentrale", "open_sensors").keys() | list) | map(attribute="attributes.friendly_name") | list | join("\r") }}'
[11:27:32][D][switch:012]: 'Notification unread' Turning ON.
[11:27:32][W][nextion:416]: Nextion reported variable name invalid!
[11:27:36][D][sensor:094]: 'RSSI': Sending state -33.00000 dBm with 0 decimals of accuracy
[11:27:39][D][sensor:094]: 'ntc_source': Sending state 1.57350 V with 2 decimals of accuracy
[11:27:39][D][resistance:039]: 'resistance_sensor' - Resistance 10207.5Ω
[11:27:39][D][sensor:094]: 'resistance_sensor': Sending state 10207.47266 Ω with 1 decimals of accuracy
[11:27:39][D][ntc:026]: 'Temperature' - Temperature: 24.5°C

@overdrivesFR
Copy link

overdrivesFR commented Oct 6, 2024

First : thanks edwardtfn, it works !
Second : I did not try putting it directly inside Alarmo as it sometimes need variation of some commands and I'm fine as it for now. I created a script, and call it upon arming failure, which is probably what you'll end up doing too Kaibob2.
My code just in case : (replace alarm entity obviously)

alias: Activation impossible NSPanel
sequence:
  - data:
      label: Activation impossible
      message: >-
        Les capteurs suivants sont ouverts :\r{{ states.binary_sensor |
        selectattr("entity_id", "in", state_attr("alarm_control_panel.alarmo",
        "open_sensors").keys() | list) |
        map(attribute="attributes.friendly_name") | list | join(", ") }} 
    action: esphome.nspanel1_notification_show
mode: single
description: ""
icon: mdi:alarm-panel

The only "problem" is that \r worked as a template but not once sent to the panel, dunno why. So a comma is fine.

@edwardtfn edwardtfn reopened this Oct 6, 2024
@edwardtfn
Copy link
Collaborator

I will take a look when back home... It should work with the \r...

@edwardtfn
Copy link
Collaborator

edwardtfn commented Oct 6, 2024

What if you go to Developer Tools, tab Actions, and then try the \r? Which error message you get?

@Kaibob2
Copy link
Author

Kaibob2 commented Oct 6, 2024

The trick is another backslash in front of \r leading to

alias: Open sensors
sequence:
  - data:
      label: Fehler Alarmanlage
      message: >-
        The following sensors are open:\r{{ states.binary_sensor |
        selectattr("entity_id", "in",
        state_attr("alarm_control_panel.alarmzentrale", "open_sensors").keys() |
        list) | map(attribute="attributes.friendly_name") | list | join('\\r')
        }} 
    action: esphome.ns_panel_wohnzimmer_notification_show
mode: single
description: ""
icon: mdi:alarm-panel

Then the newline gets parsed by esphome.

WhatsApp Bild 2024-10-06 um 16 05 46_5e5a5e68

@overdrivesFR
Copy link

overdrivesFR commented Oct 6, 2024

I tried \r\r but not \\r.
It's working, thanks.

@Kaibob2 Kaibob2 closed this as completed Oct 6, 2024
@edwardtfn
Copy link
Collaborator

Nice!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For suggestions that add new features or improve existing functionalities.
Projects
None yet
Development

No branches or pull requests

3 participants