Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Measure scripts for kasa and tuya and interpolation scripts #101

Merged
merged 2 commits into from
Aug 21, 2021

Conversation

smonesi
Copy link
Contributor

@smonesi smonesi commented Aug 21, 2021

Adding a few utils scripts:

  • measure_kasa.py: similar to measure.py that connects to Kasa devices (eg. TP-Link HS110)
  • measure_tuya.py: similar to measure.py that connects to local Tuya devices
  • interpolate_color_temp_csv.py: interpolates values in color_temp.csv files (brightness/mired steps configured in the script)
  • interpolate_hs_csv.py: interpolates values in hs.csv files (brightness/saturation/hue steps configured in the script)

@bramstroker
Copy link
Owner

Nice. Better if we would DRY the code and move the power meter logic to a seperate class PowerMeter with 3 implementations ShellyPowerMeter, TuyaPowermeter and KasaPowermeter. Than we can give the user the option to configure the powermeter they want to use, but we have to maintain a single file containing the measuring logic.
But we could also do that in a later stage. Let me know if you are up to the job. Otherwise I'll have a look later on to refactor the code.

@bramstroker
Copy link
Owner

Also I am thinking about rewriting the measure script to not use async libraries. As their is unnecessary complexity in the script now because of all the asyncio stuff, but the script it self can not do any parallel tasks (i.e. we must connect to philips HUE bridge first, than wait, set the light, wait, get the power measurement, wait etc. etc.). So if think things will get much simpler when we just use the https://github.com/studioimaginaire/phue for example and not aiohue and aioshelly.

What do you think? Do you agree?

@smonesi
Copy link
Contributor Author

smonesi commented Aug 21, 2021

I absolutely agree with the idea of refactoring with the 3 implementation and I also struggled with the async stuff (Kasa does need some async code and I had to use nest_asyncio to make it work).

However, I am no python programmer and I just wanted to contribute the code for someone else to use and eventually refine it :-)

I can still help testing and validating the results since I have both a kasa and tuya device (although I stopped using the tuya to measure because it was too unreliable). I would also help to test a ZWave implementation (I have a brand new Fibaro FGWPF-102 Plug) but I have no clue on how to use zwave-js-server-python (or any other ZWave support library) so I wasn't able to implement any ZWave code!

@bramstroker
Copy link
Owner

Will merge it now so other users can potentially use it. We can have a look into improving the code later.

@bramstroker bramstroker merged commit 5e669c0 into bramstroker:master Aug 21, 2021
@bramstroker
Copy link
Owner

Hi @smonesi. Last days I worked on new measure script. See #141. Took the two concepts (powermeter, light controller) and made them easily interchangable. Also to get rid of all the duplicated code. So you can use the HA api to control the lights, and direct Kasa API to get the power reading for example.
Ported your Kasa implementation to be included in the new script, but I have no way to test it. Could you please have a look and let me know if it works correctly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants