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

Import "switches" from Home Assistant? #1016

Open
jritsema opened this issue May 26, 2024 · 5 comments
Open

Import "switches" from Home Assistant? #1016

jritsema opened this issue May 26, 2024 · 5 comments

Comments

@jritsema
Copy link

Feature does not already exist?

I searched and did not find an existing feature request

Summarize feature

Hello. Thank you for this very useful project! When trying to import all of my lights from Home Assistant, I noticed that it only seems to import devices of type "light" and devices of type "switch" are not imported, even though I have set diyhue: include on them in my customize.yaml. Is this intentional behavior? If so, are there any workarounds?

@mariusmotea
Copy link
Member

Hi,

Yes, we import just the lights because we can emulate them in Hue lights, but other entities (like switches) we don't have a common Hue device in witch these can be emulated. Probably we can emulate the binary switches in Hue plugs....

@Paalap
Copy link
Contributor

Paalap commented May 27, 2024

Hi, its possible by adjusting/editing services/homeAssistantWS.py

Original
def change_light(self, light, data): service_data = {} service_data['entity_id'] = light.protocol_cfg['entity_id'] payload = { "type": "call_service", "domain": "light", "service_data": service_data } payload["service"] = "turn_on" if 'on' in data: if not data['on']: payload["service"] = "turn_off"

my version
def change_light(self, light, data): service_data = {} service_data['entity_id'] = light.protocol_cfg['entity_id'] if light.protocol_cfg['entity_id'].startswith("light."): payload = { "type": "call_service", "domain": "light", "service_data": service_data } elif light.protocol_cfg['entity_id'].startswith("switch."): payload = { "type": "call_service", "domain": "switch", "service_data": service_data } payload["service"] = "turn_on" if 'on' in data: if not data['on']: payload["service"] = "turn_off"

And also from
def _should_include(self, ha_state): should_include = False diy_hue_flag = None entity_id = ha_state.get('entity_id', None) if entity_id.startswith("light."):

to
def _should_include(self, ha_state): should_include = False diy_hue_flag = None entity_id = ha_state.get('entity_id', None) if entity_id.startswith("light.") or entity_id.startswith("switch."):

This is working fine for me

To make it easier: https://github.com/Paalap/diyHue-1/blob/master/BridgeEmulator/services/homeAssistantWS.py

@mariusmotea
Copy link
Member

Hi,

Please create a pull request to master branch with your changes to be more easy to follow.

@Paalap
Copy link
Contributor

Paalap commented May 28, 2024

Done in #1018

@jritsema
Copy link
Author

Wow, this is great! Thank you for the extremely fast turnaround 👍

Just to confirm, I can see that this code change brings switches into diyHue, but has someone verified that diyHue is enable to successfully turn them on/off?

Also, btw, in case it helps others. I got this working using the HASS "Switch as X" Helper, but with this change, I'll be able to remove all of that configuration 🎉

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

No branches or pull requests

3 participants