Setup as example
A smart plug with Tasmota, fixed IP-address and Idx from Domoticz: plug is also created as a switch in Domoticz so has a device name and Idx
mqtt plugin is enabled (mosquitto). I can pilot the plug from domoticz, or by pushing the button on the plug itself
As it's wifi, things can go wrong, and domoticz might claim plug is on, but not in real life.. (and I have a dozen or so devices around the house)
I want to build a generic function that checks real status of a given "device name" by querying the device itself.
And then take appropriate action(s).
For this I need to know how to retrieve the IP-address of the plug itself (I'd rather not make a list of IPs)
The command for real status retrieval is simple: http://192.168.178.77/cm?&user=xxxx&pas ... mnd=Power1
and I can already parse the json output.
Problem: I know how to go from device name to device ID
but how to go from either of those to the IP-address ?
I searched but so far failed to see where in domoticz is the link between Idx and IP-address - I guess it's in the mqtt plugin
Thanks for reading, and for any help you could provide !
Find out device's IP address, starting from DeviceName
Moderator: leecollings
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Find out device's IP address, starting from DeviceName
I don't think you will find such a relation in domoticz or in the plugin. The way MQTT works is by using topics. The MQTT broker broadcasts (publish) information in topics. All listening (subscribed) systems interested in that topic can do what the want with the information in it.
So the Only IP known to all in this setup is the IP of the MQTT broker and the MQTT broker does know all IP addresses but I have not found an easy way to get that information from this broker.
You might get some extra information from site
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 543
- Joined: Saturday 02 July 2016 5:17
- Target OS: Linux
- Domoticz version: Beta
- Contact:
Re: Find out device's IP address, starting from DeviceName
Set a static IP for the plugs MAC address at the DHCP level on your router.
Everytime the Plug connects to the network it will always get the same IP address.
Alternatively if the plug is communicating with the MQTT broker you could lookup the IP from the MQTT brokers ARP table based on the MAC address. Personally I suggest using the first method via the router which is what I use on my network.
Everytime the Plug connects to the network it will always get the same IP address.
Alternatively if the plug is communicating with the MQTT broker you could lookup the IP from the MQTT brokers ARP table based on the MAC address. Personally I suggest using the first method via the router which is what I use on my network.
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
-
- Posts: 20
- Joined: Sunday 12 February 2017 13:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Find out device's IP address, starting from DeviceName
Helloben53252642 wrote: ↑Tuesday 08 October 2019 16:21 Set a static IP for the plugs MAC address at the DHCP level on your router.
Every-time the Plug connects to the network it will always get the same IP address.
Alternatively if the plug is communicating with the MQTT broker you could lookup the IP from the MQTT brokers ARP table based on the MAC address. Personally I suggest using the first method via the router which is what I use on my network.
Thanks, I did always give static IP addresses to all my devices, on a range outside the modem's own DHCP range.
I would like the function to be for example CheckRealStatus(DeviceName,DesiredStatus)
and then the function would take care of finding out the IP, starting with DeviceName
So I'm trying to avoid having to maintain a table with pairs "domoticz device name | IP " or rather 'domoticz idx / IP" as domoticz name might change.
Seems like I'll have to build a table for my dozen devices - not too much work
The function would be CheckRealStatus(MyPlug,On), would go from MyPlug to Idx, lookup Idx in a table to find relevant IP, send the command to retrieve real status etc
-
- Posts: 543
- Joined: Saturday 02 July 2016 5:17
- Target OS: Linux
- Domoticz version: Beta
- Contact:
Re: Find out device's IP address, starting from DeviceName
You should never do this using network device names, many IoT devices are dumb enough to use the same name making the method unreliable.midomot wrote: ↑Tuesday 08 October 2019 17:51Helloben53252642 wrote: ↑Tuesday 08 October 2019 16:21 Set a static IP for the plugs MAC address at the DHCP level on your router.
Every-time the Plug connects to the network it will always get the same IP address.
Alternatively if the plug is communicating with the MQTT broker you could lookup the IP from the MQTT brokers ARP table based on the MAC address. Personally I suggest using the first method via the router which is what I use on my network.
Thanks, I did always give static IP addresses to all my devices, on a range outside the modem's own DHCP range.
I would like the function to be for example CheckRealStatus(DeviceName,DesiredStatus)
and then the function would take care of finding out the IP, starting with DeviceName
So I'm trying to avoid having to maintain a table with pairs "domoticz device name | IP " or rather 'domoticz idx / IP" as domoticz name might change.
Seems like I'll have to build a table for my dozen devices - not too much work
The function would be CheckRealStatus(MyPlug,On), would go from MyPlug to Idx, lookup Idx in a table to find relevant IP, send the command to retrieve real status etc
The most reliable way is via the DHCP setting a static IP for the MAC address.
I know it's not ideal, I use pfSense as my gateway which has a pretty good user interface for managing all my static IP assignments.
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
- erem
- Posts: 230
- Joined: Tuesday 27 March 2018 12:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Location: Amsterdam/netherlands
- Contact:
Re: Find out device's IP address, starting from DeviceName
on windows ping -a <ip-address> will resolve to the name thru reverse dns lookup
on *nix, host <ip-address> will resolve the ip address to a name.
on *nix, host <ip-address> will resolve the ip address to a name.
Regards,
Rob
Rob
Who is online
Users browsing this forum: No registered users and 1 guest