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

FEAT: Fire an event when a NEW node is found on the mesh. #21

Open
3 tasks done
asjmcguire opened this issue Dec 30, 2024 · 4 comments
Open
3 tasks done

FEAT: Fire an event when a NEW node is found on the mesh. #21

asjmcguire opened this issue Dec 30, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@asjmcguire
Copy link

Checklist

  • I have filled out the template to the best of my ability.
  • This only contains 1 feature request (if you have multiple feature requests, open one feature request for each feature request).
  • This issue is not a duplicate feature request of previous feature requests.

Is your feature request related to a problem? Please describe.

I would quite like an event to be fired on the Home Assistant Event Bus when a new node is discovered on the mesh.

Describe the solution you'd like

So the use case would something like this:
people drive through the village I live in, if there is a Met Office warning (UK) in force, upon a new node announcing itself to the mesh, I would then automatically send that node a direct message warning them about adverse weather.

It would be possible to use this in other ways though, imagine something like a treasure hunt, where as people arrive at each location, they are simply automatically sent the next clue as a direct message.

Or how about in my case for example I have the primary channel that I broadcast weather updates on less frequently, and a dedicated weather channel that I broadcast updates on much more frequently, BUT no-one knows about the sub channel with the more frequent updates. If however I could announce that the channel exists when a new node arrives on the mesh, then they could decide if they wanted to join that channel or not.

Describe alternatives you've considered

There are no alternatives.

Additional context

N/A

@broglep
Copy link
Owner

broglep commented Jan 1, 2025

I like this idea / capability to react on new nodes, but there might be some details to be figured out (e.g. if we would want to wait for a neighbour info or not). I think we could look into the mobile apps how they behave and when they notify about a new node being discovered.

I did a little experiment and it is already possible via a small detour to the entity registry and make use of the notification platform (where notify entities are created when they appear), which is quite convenient as you already have the entity id to then use as target to send a notification to

alias: React to new Meshtastic Nodes
description: ""
triggers:
  - trigger: event
    event_type: entity_registry_updated
    event_data:
      action: create
conditions:
  - condition: template
    value_template: >-
      {{ trigger.event.data.entity_id is match('notify\.mesh_node_.*',
      ignorecase=False) }}
actions:
  - action: notify.persistent_notification
    metadata: {}
    data:
      message: >-
        New Node Discovered: {{ state_attr(trigger.event.data.entity_id,
        'friendly_name') }}
      title: Meshtastic
mode: single

Maybe you can start with that and try it out to get a better feeling if that already solves some of the usecases

@asjmcguire
Copy link
Author

I will look into this workaround and see how that fits for now.
I had a little think about this over the festive period and I thought, the simplest easiest way to achieve this without having to add a whole new event. If the gateway node had an attribute - probably on the total nodes entity, that was a list of nodes that it knows about. Then I could simply use the api_node_updated event which will definitely fire when a new node appears on the mesh, and I could check whether the nodeid already exists in the known_nodes attribute on total nodes.

@broglep broglep added the enhancement New feature or request label Jan 2, 2025
@broglep
Copy link
Owner

broglep commented Jan 3, 2025

I have the workaround running and seems to work fine (with only exception that it also creates persistent notification for known nodes when you configure the gateway the first time).

A dedicated event wouldn't be that bad if this is a common use case. And I suspect it could actually be a common use case. As the mobile apps also having a notification when a new node is discovered, this is also a hint that users tend to react to new nodes, so this integration should make it also possible to react to new nodes in an automated way.

The approach of having a list of known nodes as part of the gateway is something that will be not good, home assistant warns about this, it will bloat the state history of the entity as the list will be constantly changing

@asjmcguire
Copy link
Author

asjmcguire commented Jan 4, 2025

No no, the state doesn't need to change ONLY the attributes and the attributes only get stored now when the state changes.

EDIT: IN fact I am not even certain that the attributes get stored, because this is one of the things that was a big change late last year with the presence simulation integration, it can turn lights on and off still based on what happened X number of days ago, but it can no longer set brightness or colour or the lights to what they were X number of days ago, because that information is no longer stored in the database. I'm pretty sure the Home Assistant team said something along the lines of - there is no point in storing attributes long term because there is no way to access them anyway. Which makes sense.

EDIT2: The change may in fact only be about the attributes of entities in the light domain, I need to read up on this further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants