sergey-brutsky/mi-home

Gateway and Temperature and humidity sensor

OsvaldoVallati2 opened this issue · 4 comments

Hi,
I have a Xiaomi Mi Home Gateway and two Temperature and humidity sensors that I would like to read using a script in C#.

Could you please provide an example of how to do that?

I followed the guide in https://www.domoticz.com/wiki/Xiaomi_Gateway_(Aqara) and I can get the readings from Domoticz but I cannot make it working using your library in a C# Visual Studio script.
Do I need to specify the IP address of the gateway?
What am I missing?

I am very new on this and I really appreciate some help.
Thanks!

Hi,
I'll provide you with a piece of working code a bit later

I don't know what is C# visual studio script.
You don't need to specify any password if you read data from devices.
Password is required if you'd like to send commands to your devices.

But if you just create a .net core console app the following snippet of code should be working:

public class Program
    {
        public static void Main(string[] args)
        {
            using (var miHome = new MiHome())
            {
                Task.Delay(5000).Wait();
                
                var thDevices = miHome.GetDevicesByType<ThSensor>();

                foreach (var device in thDevices)
                {
                    Console.WriteLine(device);
                }

                Console.ReadKey();
            }
        }
    }

on my PC it shows

Temperature: 17,76°C, Humidity: 57,74%, Voltage: 2,975V
Temperature: 21,32°C, Humidity: 52,63%, Voltage: 3,035V
Temperature: 21,87°C, Humidity: 50,57%, Voltage: 2,965V
Temperature: 23,61°C, Humidity: 50,62%, Voltage: 3,005V
Temperature: 22,46°C, Humidity: 52,62%, Voltage: 3,005V
Temperature: 22,72°C, Humidity: 55,17%, Voltage: 2,995V

Please let me know if it works for you.
Thanks

Hi,
Unfortunately, it doesn't work for me.
As you suggested, I did a new .net core console app and copied your code in.
On the console nothing appears.

I think it does not recognize also the gateway..Any suggestion?

  1. Check that your gateway and you PC in the same LAN (you can see UPD multicast traffic)
  2. Check that firewall doesn't block you UDP traffic
  3. Make sure that your gateway is properly configured and can see your aqara devices