AppDaemon creating an input_select

Hello all,
I’m pretty new to AppDaemon and I started writing an app which uses an input_select for the GUI inside lovelace.
I need to create an input_select and actually I do like this:

    self.set_state("input_select.my_input_select", state="", options=[""])
    self.entity_list = ["1", "2", "3", "4", "5", "6"]
    self.call_service("input_select/set_options", entity_id="input_select.my_input_select", options=self.entity_list)

The entity seems to be created but it is empty and AppDaemon log reports:
+++++++++++++++++++++++++++++++++
2020-03-08 23:16:46.774894 WARNING HASS: Error calling Home Assistant service default/input_select/set_options
2020-03-08 23:16:46.775194 WARNING HASS: Code: 400, error: 400: Bad Request
+++++++++++++++++++++++++++++++++

Instead if I create it inside homeassistant yaml file the input_select in AppDaemon is correctly filled by the same instructions tat failed before:

self.entity_list = ["1", "2", "3", "4", "5", "6"]
    self.call_service("input_select/set_options", entity_id="input_select.my_input_select", options=self.entity_list)

To me there is an issue not in the call_service but into the set_state.

What can I do?

Thank you.
Ignazio

There seem to be a missing quote around the 2. Is that just copy & paste error? :slight_smile:

I’m not sure, but I don’t think you can create working input_selects from AppDaemon.

Yes is a typo…

Yes I’m starting to think the same.
I have issue also with input_boolean.
I would like to know why…
I thought that AppDaemon could replace 100% yaml file configuration not only for automations but also for defining sensors and other data structures.
If this is not the case I would like to read it somewhere into the official documentation but I was not able to find anything…
Thanks!

Ignazio

As far as I know, only creation of certain entities is possible such as a sensor.

@ReneTode probably knows more about this.

Thanks in fact I just found this very interesting discussion:

This evening I will try both with input_select and input_boolean.

:slight_smile:

Ok great!
I tried with input_boolean and it works perfectly.

@ReneTode what about input_text or input_select?
I’m not able to manage it completely by AppDaemon :frowning:
Thanks.
Ignazio

Edit: I was wrong after restarting HA all input_boolean created this way disappeared :frowning:

If you create an entity whose domain is not configed in the config file, you should register related service manually.

Hi I tried to register the service:
I have called the register_service function which register the set_value service.
This service simply log a string in case of that event called.
Then I wait for some event with listen_event which eventually shall run the call back when any service is called.
The call back change_state_cb would log the event name.
Nothing happen when the input_text created in the GUI is changed.

class InputText(hass.Hass):

    def initialize(self):
        self.input_text = self.args["name"]
        self.log(self.input_text)
        self.register_service("input_text/set_value", self.set_value_cb)
        if not self.entity_exists(self.input_text):
            self.set_state(self.input_text, state = "")
        self.listen_event(self.change_state_cb, event = "call_service")

    def change_state_cb(self,event_name,data, kwargs):
        self.log("event_name:"+event_name)
        #self.call_service("input_text/set_value", entity_id = self.input_text, value = "red")

    def set_value_cb(self):
      self.log("set_value_cb")

What should I try?

The ‘register_service’ api in appdaemon is meant to create your own service.
When HA starts, if input_text is configed, the following service will be register: 1. set_value 2. reload.

You can see how are these services registered in ha log. It’s been a long time, so I can’t recall it totally.
But here’s what I found in my ad which is an app that create a input_select entity.

class HDMImatrix(hass.Hass):

    def initialize(self):
        self.climate = self.args['climate_id']
        self.input_source = self.args['input_source']
        self.entities = self.args['entities']
        # self.listen_event(self.ha_restart, event='call_service', domain='homeassistant', service='restart')
        self.fire_event('service_registered', domain="input_select", service="select_option")
        self.fire_event('service_registered', domain="input_select", service="set_options")
        self.fire_event('service_registered', domain="input_select", service="select_previous")
        self.fire_event('service_registered', domain="input_select", service="select_next")
        for entity in self.entities:
            friendly_name = self.entities[entity]['friendly_name']
            icon = self.entities[entity]['icon']
            cmds = self.entities[entity]['cmds']
            globals()['self.'+entity+'_list'] = dict(zip(self.input_source,cmds))
            self.set_state(entity, state = '请选择信号源', attributes = {'options': self.input_source, 'friendly_name': friendly_name, 'icon': icon})
            self.listen_select_handle = self.listen_event(self.select_input, event='call_service', domain="input_select", service='select_option', entity=entity)

There are 4 services that I registered mannully. You can try this.

2 Likes

Could you please give me an example of apps.yaml calling HDMImatrix class?
Cannot make it working.

Thank you

HDMI_Matrix:
  module: HDMI_Matrix
  class: HDMImatrix
  host: 10.0.0.179
  climate_id: climate.aqara_air_conditioning_companion_1
  input_source:
    - PC
    - Movie Player
    - PS4
    - Xbox One
  entities:
    input_select.hdmi_output_a:
      friendly_name: 屏幕信号
      icon: mdi:monitor
      cmds:
        - FE00000000000094701fff9Aff080026270E003600AB00E401C603810FAA138825A843000000000000000001010101010101010000010101000100010100000001000105420742061A
        - FE00000000000094701fff9Bff0800282711003600AB00E401C503800FA61388259C4300000000000000000101010101010101000101010100000001000000000101010542074207420651
        - FE00000000000094701FFF9dFF0800262711003600AB00E301C503800FA2138825954300000000000000000101010101010101000000010100010001010100000100010542074206FC
        - FE00000000000094701FFF9eFF0800262712003600AA00E401C503800FA51388259A430000000000000000010101010101010100010100010000000100000100010101054207420604
    input_select.hdmi_output_b:
      friendly_name: 投影信号
      icon: mdi:projector
      cmds:
        - FE00000000000094701fff96ff080026270A003700AB00E501C303820FA6138825A043000000000000000001010101010101010100000101000100000101000001000105420742060E
        - FE00000000000094701fff97ff080026270B003600AB00E501C603810FAA138825A843000000000000000001010101010101010000000101000000010101000001010105420742061B
        - FE00000000000094701fff98ff080026270C003600AB00E401C503800FA51388259C430000000000000000010101010101010101000101010001000001000000010001054207420607
        - FE00000000000094701fff99ff080026270D003600AB00E401C503800FA51388259D430000000000000000010101010101010100000101010000000101000000010101054207420608