flavio-fernandes / mqtt2kasa Goto Github PK
View Code? Open in Web Editor NEWPython-based project that provides wrapper to python-kasa for MQTT access
License: MIT License
Python-based project that provides wrapper to python-kasa for MQTT access
License: MIT License
When running as documented I see the following error...
Traceback (most recent call last):
File "mqtt2kasa/main.py", line 12, in
from mqtt2kasa.keep_alive import (
File "/home/pi/kasa/mqtt2kasa/mqtt2kasa/keep_alive.py", line 76, in
kasas: dict[str, Kasa], kas: dict[str, KeepAlive], mqtt_send_q: asyncio.Queue
TypeError: 'type' object is not subscriptable
My configuration looks like this...
knobs:
# Note: normally you don't set these... here just to show how to
# devel and debug
# log_to_console: false
# log_level_debug: false
mqtt:
# ip/dns for the mqtt broker
host: 192.168.35.90
globals:
# every location will be managed using a unique mqtt topic
# unless explicitly specified, this format will be used
topic_format: /{}/switch
# kasa will monitor the current state of the device every
# poll interval, in seconds. You can override on a per device
poll_interval: 11
locations:
# coffee maker. To turn it on, use mqtt publish
# topic: /coffee_maker/switch payload: on
# subscribe to /coffee_maker/switch to know its state
living_room_lights
host: 192.168.35.103
desk_lights:
host: 192.168.35.120
Any help would be appreciated.
Not sure how to get this running. Attempted the instructions but hitting issues with the source
command of create-env.sh
$ ./mqtt2kasa/bin/create-env.sh && \
> source ./env/bin/activate && \
> export PYTHONPATH=${PWD}
++ dirname ./mqtt2kasa/bin/create-env.sh
+ cd ./mqtt2kasa/bin
+ BIN_DIR=/home/pi/mqtt2kasa/mqtt2kasa/bin
+ PROG_DIR=/home/pi/mqtt2kasa/mqtt2kasa
+ TOP_DIR=/home/pi/mqtt2kasa
+ pushd /home/pi/mqtt2kasa
~/mqtt2kasa ~/mqtt2kasa/mqtt2kasa/bin
+ '[' '!' -e ./env ']'
+ source ./env/bin/activate
./mqtt2kasa/bin/create-env.sh: line 15: ./env/bin/activate: No such file or directory
Not sure what how to get this file...
Hello,
python-kasa just introduce the notion of child device for device like the KS240. It is required to be able to control each switch in a multi-device device. It would be great if it was added.
Thank you!
Hello,
Newer device started to use a new protocol and now require an authentication to be used. In python-kasa, we can either set KASA_USERNAME and KASA_PASSWORD so it's used globally or specify --username and --password on the command line to specify it.
Exemple is KS240 device that require it.
Thank you
Quick fix is to update requirement.txt to have aiomqtt==1.2.1
Longer fix is to follow https://sbtinstruments.github.io/aiomqtt/migration-guide-v2.html
I have tried to use the emeter output, but it has a couple of issues:
I have edited the code to remove the <> send multiple messages. Can this be incorporated in the standard code?
`async def handle_emeter_event_kasa(
kasa_emeter: KasaEmeterEvent, run_state: RunState, mqtt_send_q: asyncio.Queue
):
kasa = run_state.kasas.get(kasa_emeter.name)
if not kasa:
logger.warning(
f"Unable to find device with name {kasa_emeter.name}. Ignoring kasa emeter event"
)
return
topic = f"{kasa.topic}/emeter"
payload = kasa_emeter.emeter_status
payload = payload.replace('<', '')
payload = payload.replace('>', '')
logger.info(
f"Kasa emeter event requesting mqtt for {kasa_emeter.name} to publish"
f" {topic} as {payload}"
)
await mqtt_send_q.put(MqttMsgEvent(topic=topic, payload=payload))
myList = payload.split()
print(myList)
for item in myList:
print( item )
topic = f"{kasa.topic}/emeter/" + item.split('=')[0]
print( 'topic =' + topic)
payload = item.partition("=")[2]
await mqtt_send_q.put(MqttMsgEvent(topic=topic, payload=payload))
`
What's really missing: mqtt2kasa does not publish the EmeterStatus, which is reported by kasa.
Output of kasa --host hs110 --type plug
== Current State == <EmeterStatus power=0.952 voltage=234.378 current=0.015 total=0.482>
When running the install command ex: sudo python3 setup.py install
The following SemanticVersion exception will be thrown:
ValueError: git history requires a target version of pbr.version.SemanticVersion(0.0.3), but target version is pbr.version.SemanticVersion(0.0.1)
I fixed this by updating version in the file: setup.cfg to 0.0.3
Currently the publish handler uses the default retain payload flag of the mqtt library which is "false". This should be configurable either globally or per device.
I retain payloads for all my kasa switches when publishing to the topic. However, if I directly turn the device on or off from the switch, when mqtt2kasa polls the devices it will see the changed state and publish to the topic with retain = false
.
Since I retain for all devices, I manually modified mqtt.py to publish with retain = true
as a workaround. Additionally the qos
value could be configurable the same way.
I am installing it on a Ubuntu server (Ubuntu 22.04.2 LTS).
During the first install I got the same error as : #5
Second install I get an exception raised due to invalid files. Not sure what is gong on, but I think that there is a problem somewhere.
(env) gck@emonpi:~/mqtt2kasa$ python3 mqtt2kasa/main.py ./data/config.yaml Traceback (most recent call last): File "/home/gck/mqtt2kasa/mqtt2kasa/main.py", line 263, in <module> log.initLogger() File "/home/gck/mqtt2kasa/mqtt2kasa/log.py", line 28, in initLogger logHandlerAddress = _log_handler_address( File "/home/gck/mqtt2kasa/mqtt2kasa/log.py", line 16, in _log_handler_address raise Exception("Invalid files: %s" % ", ".join(files)) Exception: Invalid files: /run/systemd/journal/syslog, /var/run/syslog, /device/log (env) gck@emonpi:~/mqtt2kasa$
Hi
Before anything, thanks for library/module!
My understanding, this library/module uses 'kasa-python' internally which supports setting brightness "kasa --host 192.168.0.15 brightness 50". Does the library/module support setting brightness via mqtt? If not, any tips how to add the support (files to update, commands etc)?
Thanks!
Getting this error. Any suggesstions?
(env) pi@home-assistant-pi4:~/sh/kasa/mqtt2kasa $ python3 mqtt2kasa/main.py ./data/config.yaml
Traceback (most recent call last):
File "mqtt2kasa/main.py", line 12, in
from mqtt2kasa.keep_alive import (
File "/home/pi/sh/kasa/mqtt2kasa/mqtt2kasa/keep_alive.py", line 76, in
kasas: dict[str, Kasa], kas: dict[str, KeepAlive], mqtt_send_q: asyncio.Queue
TypeError: 'type' object is not subscriptable
I am getting strange repeated messages which are alternating on/off. Not quite sure what is going on.
This is the output from whening running the script in the foreground.
Any ideas?
When I restart the script the problem goes.
Device dehumidifier is too busy to take request to be set as on Device dehumidifier is too busy to take request to be set as off Device dehumidifier is too busy to take request to be set as on Device dehumidifier is too busy to take request to be set as off Device dehumidifier is too busy to take request to be set as on Device dehumidifier is too busy to take request to be set as off Device dehumidifier is too busy to take request to be set as on Device dehumidifier is too busy to take request to be set as off Device dehumidifier is too busy to take request to be set as on Device dehumidifier is too busy to take request to be set as off Device dehumidifier is too busy to take request to be set as on Device dehumidifier is too busy to take request to be set as off Device dehumidifier is too busy to take request to be set as on Device dehumidifier is too busy to take request to be set as off Device dehumidifier is too busy to take request to be set as on Device dehumidifier is too busy to take request to be set as off Device dehumidifier is too busy to take request to be set as on Device dehumidifier is too busy to take request to be set as off Device dehumidifier is too busy to take request to be set as on Device dehumidifier is too busy to take request to be set as off Device dehumidifier is too busy to take request to be set as on Device dehumidifier is too busy to take request to be set as off Device dehumidifier is too busy to take request to be set as on
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.