Skip to content

Add power on method to call a service#190

Open
rogelio-o wants to merge 1 commit intoollo69:masterfrom
rogelio-o:powe_on_service
Open

Add power on method to call a service#190
rogelio-o wants to merge 1 commit intoollo69:masterfrom
rogelio-o:powe_on_service

Conversation

@rogelio-o
Copy link

I want to call an HA service to power on the TV instead of using the WOL method provided. In my case, I am using HA in the Kubernetes environment where the WOL does not reach the LAN where the TV is, and instead of that, I use the rest_command service.

I previously used the official integration, where I can configure turn_on_action to call that service. This MR will make it equivalent to that configuration. Even you could remove the WOL implementation, and the user could rely on the Wake On LAN HA integration by calling its service.

@ollo69
Copy link
Owner

ollo69 commented Dec 12, 2022

Could you rebase this?

@rogelio-o
Copy link
Author

Could you rebase this?

Sure! Done.

Comment on lines +489 to +500
vol.Required(
CONF_POWER_ON_METHOD,
default=options.get(
CONF_POWER_ON_METHOD, str(PowerOnMethod.WOL.value)
),
): SelectSelector(_dict_to_select(POWER_ON_METHODS)),
vol.Required(
CONF_POWER_ON_SERVICE_DATA,
default=options.get(
CONF_POWER_ON_SERVICE_DATA, "{}"
),
): cv.string,
Copy link
Owner

@ollo69 ollo69 Dec 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this way we are going to provide a SmartThings option also if SmartThings is not enabled (not good) and we also add a text field that should be useless in some cases. This will probably confuse "normal" user and cause false issues, because I'm trying to simplify option flow (I will introduce some changes shortly), I do not like very match this approach.

I suggest to add only the text field in the advanced option:

  • if it contain some values, the power-on based on service will be used (may be you could also hide the power on method field in main form in this case)
  • if empty, everything will normally

)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers import config_validation as cv, entity_registry as er
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not import cv only for cv.string. Is enought use str

@ollo69 ollo69 self-assigned this Dec 15, 2022
@ollo69 ollo69 mentioned this pull request Jan 6, 2024
@felipecrs
Copy link

Just to mention that Home Assistant official integrations with similar needs are adopting the trigger mechanism, where you can implement your own automation for.

Example, triggers when the TV is requested to power on:

platform: samsungtv.turn_on
entity_id: media_player.samsung_tv

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.

3 participants