sergey-brutsky / mi-home Goto Github PK
View Code? Open in Web Editor NEWС# API for Xiaomi Mi Home devices
License: MIT License
С# API for Xiaomi Mi Home devices
License: MIT License
Hi, how do I discover which available methods there are for any given device please?
E.g gateway?.EnableLight() is one that you mention in your resdme but how do I find all methods that can be used? I am thinking about trying to use this for my Roborock s5 max vacuum.
Thanks Ben
Hi. I tried your code example from MiHomeConsole
. And it is not working for me.
miHome.GetGateway()
is always null and miHome.GetDevices()
is always empty. I tried both ways - with password and SSID and without them.
I tried to connect to router via Ethernet cable and via Wi-Fi.
IPTV router setting is enabled:
I do not have Hyper-V/Virtual box network adapters:
My firewall and antivirus are disabled.
I created 4 firewall rules to allow TCP and UDP ingoing and outgoing connection on 9898 port.
I created the forwarding rule for my router:
Domoticz is also not working for me. It stuck on http://127.0.0.1:8080/#/Devices
page:
Have you any more suggestions?
Thank you in advance!
Hi, I'm looking to buy a smart Power socket that I can control programmatically.
I'm wondering if this package will allow me to control "Xiaomi Mi Smart Plug Wi-Fi (GMR4015GL)" on it's own without a gateway device?
Here is the code for the Wireless Switch, have one at home and are running your library with this added Switch, works nicely.
using System;
using Newtonsoft.Json.Linq;
namespace MiHomeLib.Devices
{
public class WirelessSwitch : MiHomeDevice
{
public event EventHandler OnClick;
public event EventHandler OnDoubleClick;
public event EventHandler OnLongClickRelease;
public event EventHandler OnLongClickPress;
public WirelessSwitch(string sid) : base(sid, "switch")
{
Status = "idle";
}
public float? Voltage { get; set; }
public string Status { get; private set; }
public override void ParseData(string command)
{
var jObject = JObject.Parse(command);
if (jObject["status"] != null)
{
Status = jObject["status"].ToString();
if (Status == "click")
{
OnClick?.Invoke(this, EventArgs.Empty);
}
else if (Status == "double_click")
{
OnDoubleClick?.Invoke(this, EventArgs.Empty);
}
else if (Status == "long_click_press")
{
OnLongClickPress?.Invoke(this, EventArgs.Empty);
}
else if (Status == "long_click_release")
{
OnLongClickRelease?.Invoke(this, EventArgs.Empty);
}
}
if (jObject["voltage"] != null && float.TryParse(jObject["voltage"].ToString(), out float v))
{
Voltage = v / 1000;
}
}
public override string ToString()
{
return $"Status: {Status}, Voltage: {Voltage}V";
}
}
}
After updating gateway to the latest avaible version (2.61.3) I can't find any device anymore... I tryed controlling if lan mode was still active, but there's no way to have the 2 more menus tapping on the version number. Any idea?
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!
it will get 0 devices first time,
and get error message when dispose miHome object, error:
The given key 'ctrl_ln2.aq1' was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at MiHomeLib.MiHome.GetOrAddDeviceByCommand(ResponseCommand cmd)
at MiHomeLib.MiHome.ProcessReport(ResponseCommand cmd)
at MiHomeLib.MiHome.StartReceivingMessages(CancellationToken ct)
but if i use debugger go back to new MiHome, it will get devices (but not aqua wall switch)
And the above error will continue display.
Please help, thanks.
Hi,
I tried your example code snippets but nothing happened. I tried to search for all devices, also tried to reach my gateway, but can't see anything (though I have a switch, a cube and a plug). How should these events work? For example when should the OnSocketPlug event fire exactly?
I checked your python script which you mentioned at an other issue, and I receive my gateway's heartbeats, so I guess I should reach it.
Thank you very much in advance,
Peter
Здравствуйте!
Имеется следующая проблема. Инициализирую объект MiHome c паролем и сидом гейта.
Определяются все подключенные к нему устройства. После подписки по сиду датчика влажности и температуры на события ничего не происходит.
miHome = new MiHome("j3kvvz9x4ufgvyzr", "7c49eb88ce6f"); Task.Delay(10000).Wait(); var thSensor = miHome.GetDeviceBySid<ThSensor>("158d0002b54977"); thSensor.OnHumidityChange += ThSensor_OnHumidityChange; thSensor.OnTemperatureChange += ThSensor_OnTemperatureChange;
события не файрятся =(
Помогите пожалуйста разобраться с проблемой. В какую сторону копать.
I want to buy the Door/Window sensor and integrate it to my windows app. Do I need to buy also the Gateway or just the door sensor is enough?
Can you please enlighten me?
Hi,
Any plan to integrate 360 mi camera as a device ?
Regards
Sybaris
Hi Sergey,
I was wondering if this could be used to relay events from xiaomi devices to somewhere like Hubitat or WebCore? I use Xiaomi devices connected directly to Hubitat and SmartThings hubs but find that the xiaomi devices always drop their connections and the devices do not report back to the hubs in a timely enough manner. It would be more stable to use the actual Xiaomi Gateway hub and then relay the events from the devices to my other hubs. Do you think this would work?
thanks
I have encountered an exception related to the device list that is owned by the class MiHome. After digging through the behaviour of this class and the async task(s) that add items to the list it is clear that exposing this list as public is dangerous. I have changed the code on my machine to use a ConcurrentDictionary<string, MiHomeDevice> where the key is the SID of the MiHomeDevice (which should be unique). So now adding devices is thread-safe when other places are using this collection.
Also the GetDevices() function returns a List which i construct from the concurrent dictionary before giving the list to the caller, like so:
List<MiHomeDevice> devices = _devicesList.Values.ToList()
No problems so far.
I tried to connect to mi gateway which locates at the same LAN. However, i didn't see any multicast message located in 224.0.0.50:9898, instead, i saw the multicast on 224.0.0.251:9898. When I send the discover message get_id_list to 224.0.0.251, the returned message is not received by the program, the socket is not able to connect. Here is the error: SocketException: The socket is not connected
System.Net.Sockets.Socket.Shutdown (System.Net.Sockets.SocketShutdown how) (at <3845a180c26b4889bc2d47593a665814>:0)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.