# mDNS-SD event when record changes

**URL:** <https://community.homey.app/t/mdns-sd-event-when-record-changes/84354>\
**Category:** Developers\
**Created:** [July 11, 2023, 7:52am UTC](https://community.homey.app/t/mdns-sd-event-when-record-changes/84354 "2023-07-11T07:52:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![EscAbe](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/escabe/32/13077_2.png) [@EscAbe](https://community.homey.app/u/EscAbe)\
**Post date:** [July 11, 2023, 7:52am UTC](https://community.homey.app/t/mdns-sd-event-when-record-changes/84354/1 "2023-07-11T07:52:58Z")

</div>

I am trying to implement a driver for a switch device which publishes its current state (on/off) in a TXT mDNS-SD record. I.e. when discovery is requested it publishes its mDNS-SD record including the TXT with its current state, but it also proactively publishes a new mDNS-SD record whenever the state changed. I’d like to use this to ensure my device state in Homey is up to date (especially if it changed outside of Homey).

Overall [mDNS-SD support built-in to Homey](https://apps.developer.homey.app/wireless/wi-fi/) discovery works well with the device. I can successfully use it for initial pairing and in my device `onDiscoveryResult`, `onDiscoveryAvailable` work fine; as documented though, `onDiscoveryAvailable` only gets called once upon first discovery/initialization.

**Is there any way in the built-in mDNS-SD support where my App/Driver/Device can be notified/any event I can subscribe to when the mDNS-SD record changed?**

I could probably build something myself based on [multicast-dns](https://www.npmjs.com/package/multicast-dns) but would prefer to make use of the built-in mDNS-SD support if it _can_ do this.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [July 11, 2023, 8:05am UTC](https://community.homey.app/t/mdns-sd-event-when-record-changes/84354/2 "2023-07-11T08:05:12Z")

</div>

Have you tried using the `onDiscoveryAddressChanged` and `onDiscoveryLastSeenChanged` methods to see if they get triggered?

---

<div class="post-metadata">

**Author:** ![EscAbe](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/escabe/32/13077_2.png) [@EscAbe](https://community.homey.app/u/EscAbe)\
**Post date:** [July 11, 2023, 8:59am UTC](https://community.homey.app/t/mdns-sd-event-when-record-changes/84354/3 "2023-07-11T08:59:03Z")

</div>

Yes, I have defined a `onDiscoveryAddressChanged` and `onDiscoveryLastSeenChanged`, but they do _not_ appear to be triggered _when that TXT record changes_.

Which makes sense I suppose, `onDiscoveryAddressChanged` should only trigger if the same device is seen again with a new IP.

Not entirely sure how `onDiscoveryLastSeenChanged` is supposed to behave. [Documentation says](https://apps-sdk-v3.developer.homey.app/Device.html#onDiscoveryLastSeenChanged):

> This method is called when the device has been found again.

Which is somewhat vague. “found again” does that mean is first had to be lost (i.e. the device was not seen for quite a while, considered to be offline and then it popped up again)? Which unfortunately would not directly help in my situation. Or is a “found again” simply “seen again” (with or without any modified records)? That would be exactly what I need, but it does not appear to work in practice then.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [July 11, 2023, 9:06am UTC](https://community.homey.app/t/mdns-sd-event-when-record-changes/84354/4 "2023-07-11T09:06:31Z")

</div>

I agree it’s vague.

If none of the methods are triggered, it’s probably not possible to do this with the built-in discovery system, which is really intended for discovery only and not for state updates.
