Home assisatnt and Logitech peripherals (mouse/keyboard)


Anyone knows how can I integrate my logitech keyboard and mouse into Home Assistant? I just want to make some automations which detect the battery level of my G502 and G915 peripherals, in order to switch power for wireless charging.

Thank you in advance!

Nobody? :frowning:

1 Like

At least this page went to 2nd place of googling for “home assistant logitech mouse”.
Well I also though it would be nice to use a wireless mouse as event_triger/sensor, like horizontal/vertical shake, clicks etc. It definitely requires BLE/Bluetooth stick on HASS device or device-bridge that would simulate mouse over IP, some ESP8622 thing.

1 Like

I am trying something else… I have a G915 wireless keyboard and I modified it just a bit by adding a wireless coil in the back and a wireless charger where I put the keyboard when I don’t use it… I just want to turn on the wireless power on if keyboard battery is less than xx% and stop charging at 99% … But not even logitech wants to help with an api or something…

Well, theoretically you need super precise power consumption monitor. Then learn how battery charging change consumption load (charging curve) and then build triggers on top of the riching edge levels. That would work not only with Logitech mouse but with any battery-based device.

Yes, but super super mega precise :smiley:

It’s been two years since this post, has anyone found a way to do this. @Pickone I know Logitech has an SDK now for LED Illumination as well as other things.

I looked into those infos, but I didn’t find anything good to use… Now I am searching for a plugin which can be used with EventGhost, to capture notifications from logitech app, maybe I can use them in order to achieve what I need

If controlling the RGB is what you want, you can use the OpenRGB integration. I use it with my G502.

I want to know when the battery is low and when it is full charged :slight_smile:

1 Like

Here is how you can do this.

First of all, you need:

  • NodeRed
  • G Hub software on your PC where mouse and keyboard are plugged in

G Hub software’s websocket on Windows is only listening localhost. So you need to port forward 9010 on localhost to You can do this in administrator cmd by running:
netsh interface portproxy add v4tov4 listenport=9010 listenaddress= connectport=9010 connectaddress=

This, of course, opens a websocket port to the local network, which can lead to security problems if misused.

You can remove this rule by running:
netsh interface portproxy delete v4tov4 listenport=9010 listenaddress=

Or remove all rules:
netsh interface portproxy reset

Next you need to import following flow to NodeRed:

[{"id":"6b10c94ed0884a2f","type":"websocket in","z":"5c54fd74201b2007","name":"","server":"","client":"6ece96e1def0e92f","x":2520,"y":4760,"wires":[["23f4f6286d62b9c8"]]},{"id":"4f0baaeff39483cb","type":"websocket out","z":"5c54fd74201b2007","name":"","server":"","client":"6ece96e1def0e92f","x":2520,"y":4720,"wires":[]},{"id":"abafe756c436317c","type":"inject","z":"5c54fd74201b2007","name":"Get devices daily","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 12 * * *","once":true,"onceDelay":0.1,"topic":"","payload":"{\"path\":\"/devices/list\",\"verb\":\"GET\"}","payloadType":"json","x":2070,"y":4720,"wires":[["4f0baaeff39483cb"]]},{"id":"23f4f6286d62b9c8","type":"json","z":"5c54fd74201b2007","name":"","property":"payload","action":"obj","pretty":false,"x":2710,"y":4760,"wires":[["a3ed512a1e7068af"]]},{"id":"a3ed512a1e7068af","type":"function","z":"5c54fd74201b2007","name":"Handle devices","func":"if (msg.payload.path === \"/devices/list\") {\n    // NOLLAA DATA MUISTI\n    if (flow.get('ghub') !== undefined)\n        flow.set('ghub', undefined);\n\n    let devices = [];\n\n    msg.payload.payload.deviceInfos.forEach(function (e) {\n        if (e.connectionType === \"WIRELESS\")\n            var tmp = {\n                deviceModel: e.deviceModel,\n                id: e.id,\n            };\n        devices.push(tmp);\n    });\n\n    flow.set('ghub', devices);\n    return null;\n}\n\nif (msg.payload.path.startsWith(\"/battery/\")) {\n    let devices = flow.get('ghub');\n    var tmp;\n\n    devices.forEach(function(e) {\n        if (e.id.trim() === msg.payload.payload.deviceId.trim()) {\n            e.battery = msg.payload.payload.percentage;\n            e.charging = msg.payload.payload.charging;\n            tmp = e;\n        }\n    });\n\n    flow.set('ghub', devices);\n    msg.payload = tmp;\n    return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2860,"y":4760,"wires":[["8a2ecd86a1a51433"]]},{"id":"84ade348d658e27a","type":"function","z":"5c54fd74201b2007","name":"For every device","func":"flow.get('ghub').forEach(function(e) {\n    var tmp = {\n        \"path\": \"/battery/\" + e.id + \"/state\",\n        \"verb\": \"GET\"\n    };\n    msg.payload = tmp;\n    node.send(msg);\n});","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2300,"y":4760,"wires":[["4f0baaeff39483cb"]]},{"id":"96dc1d0ed1a99fdd","type":"inject","z":"5c54fd74201b2007","name":"Update device sensors","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1200","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":2090,"y":4760,"wires":[["84ade348d658e27a"]]},{"id":"d06034d2c40237f4","type":"ha-sensor","z":"5c54fd74201b2007","name":"Logitech G604 hiiri","entityConfig":"5bcdcc43ddbf4acc","version":0,"state":"payload.battery","stateType":"msg","attributes":[{"property":"charging","value":"payload.charging","valueType":"msg"}],"inputOverride":"allow","outputProperties":[],"x":2730,"y":4880,"wires":[[]]},{"id":"8a2ecd86a1a51433","type":"switch","z":"5c54fd74201b2007","name":"Which device?","property":"payload.deviceModel","propertyType":"msg","rules":[{"t":"eq","v":"g915","vt":"str"},{"t":"eq","v":"g604","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":2540,"y":4860,"wires":[["ba94d6afc2de6ae8"],["d06034d2c40237f4"]]},{"id":"ba94d6afc2de6ae8","type":"ha-sensor","z":"5c54fd74201b2007","name":"Logitech G915 näppäimistö","entityConfig":"d64be8a5624713fe","version":0,"state":"payload.battery","stateType":"msg","attributes":[{"property":"charging","value":"payload.charging","valueType":"msg"}],"inputOverride":"allow","outputProperties":[],"x":2760,"y":4840,"wires":[[]]},{"id":"353b5a00c79e43bd","type":"comment","z":"5c54fd74201b2007","name":"LOGITECH WIRELESS DEVICES SENSORS FROM GHUB WEBSOCKET --> SEE INSTRUCTIONS","info":"Computer running G Hub software:\n\n- For websocket connection to be available, you must port forward 9010 port on windows\n- G Hub software is only listing localhost\n\nRun in administrator cmd:\nnetsh interface portproxy add v4tov4 listenport=9010 listenaddress= connectport=9010 connectaddress=\n\nTo remove:\nnetsh interface portproxy delete v4tov4 listenport=9010 listenaddress=\n\nTo remove all forwards:\nnetsh interface portproxy reset","x":2320,"y":4680,"wires":[]},{"id":"6ece96e1def0e92f","type":"websocket-client","path":"ws://","tls":"","wholemsg":"false","hb":"0","subprotocol":"json"},{"id":"5bcdcc43ddbf4acc","type":"ha-entity-config","server":"9d549391.d2a88","deviceConfig":"","name":"Logitech G604 hiiri","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Logitech G604 hiiri"},{"property":"icon","value":"mdi:mouse"},{"property":"entity_category","value":""},{"property":"device_class","value":"battery"},{"property":"unit_of_measurement","value":"%"},{"property":"state_class","value":""}],"resend":false,"debugEnabled":false},{"id":"d64be8a5624713fe","type":"ha-entity-config","server":"9d549391.d2a88","deviceConfig":"","name":"Logitech G915 näppäimistö","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Logitech G915 näppäimistö"},{"property":"icon","value":"mdi:keyboard"},{"property":"entity_category","value":""},{"property":"device_class","value":"battery"},{"property":"unit_of_measurement","value":"%"},{"property":"state_class","value":""}],"resend":false,"debugEnabled":false},{"id":"9d549391.d2a88","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

In NR you need to

  • set your PC’s IP address to websocket nodes
  • adjust switch-node to include your device models
  • and set individual sensors according to your preferences.

Hi! Any idea to do this without NodeRed? With just Yaml?

In short, you can’t (or at least I’m not aware of any way) unless someone makes a custom integration to Home Assistant.

I was wrong. It is also possible to install a program on the PC that you can use to make REST calls.

This is what I found in the past, but i didn’t offer any chance to use it :smiley: I will try it. Thanks

Edit: Seems to work nice <3

1 Like

I run a python script on my windows machine that tracks my G703 mouse battery and publishes battery level, charging state (charging/not charging) to mqtt. I made some custom mqtt sensors and binary sensors in HA to integrate the whole thing. Works great and I use it to notify when I need to charge and when it’s fully charged, It works great for my needs. I poll the info from G HUB, but it’s far from just plug and play.

It would be cool to have something more polished but I wouldn’t know how to do that.

I have installed this on my computer GitHub - andyvorld/LGSTrayBattery: A tray app used to track battery levels of wireless Logitech mouse.

And in Home Assistant I made some scrape sensors like this, using variable addon as well.
It is working flowless

### Logitech Devices
- resource:
  scan_interval: 1576800000
    - name: Logitech Primary Mouse G502 Battery
      unique_id: logitech_primary_mouse_g502_battery
      icon: mdi:battery
      select: "battery_percent"
      device_class: battery
      unit_of_measurement: "%"
      value_template: >-
        {% if is_number(value.split(',')[:1] | regex_replace('[^\\d]','') | float | round(0)) %}
        {% set var = value.split(',')[:1] | regex_replace('[^\\d]','') | float | round(0) %}
        {% if var >= 1 %}
        {{ var }}
        {% else %}
        {{ state_attr("sensor.variable_last_state","logitech_primary_mouse_g502_battery") }}
        {% endif %}
        {% else %}
        {{ state_attr("sensor.variable_last_state","logitech_primary_mouse_g502_battery") }}
        {% endif %}