Skip to content

Instantly share code, notes, and snippets.

@executed
Last active August 17, 2024 02:12
Show Gist options
  • Save executed/4ff287f3aba31ae1c6bf1dcc84efce28 to your computer and use it in GitHub Desktop.
Save executed/4ff287f3aba31ae1c6bf1dcc84efce28 to your computer and use it in GitHub Desktop.
HASS integration that accepts input_text helper entity_id and returns input text helper value on HASS API call
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import (
HomeAssistant,
ServiceCall,
ServiceResponse,
SupportsResponse,
)
from homeassistant.helpers import config_validation as cv, entity_platform, service
from homeassistant.util.json import JsonObjectType
SEARCH_ITEMS_SERVICE_NAME = "return_input_text_val"
DOMAIN = "cst"
DEFAULT_NAME = "Return Input Text Value"
async def async_setup(hass, config):
async def return_input_text_val(call) -> ServiceResponse:
entity_id = call.data.get("entity_id")
state = hass.states.get('input_text.' + entity_id)
value = state.state
return {"value": value}
hass.services.async_register(DOMAIN, "return_input_text_val", return_input_text_val, schema=None, supports_response=SupportsResponse.ONLY)
return True;
@executed
Copy link
Author

executed commented Aug 17, 2024

Example call: http://192.168.0.999:8123/api/services/cst/return_input_text_val?return_response

Auth. token bearer needs to be included in header as well
Entity ID of HASS helper needs to be included too:
{
"entity_id": "maryanochka_alarm_time_list"
}

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