bob1de / hass-apps

Some useful apps and snippets to empower Home Assistant and AppDaemon even more.
Apache License 2.0
85 stars 23 forks source link

[schedy] switch state value wrapped in list: '["on"]' instead of "on" #58

Closed mihlit closed 3 years ago

mihlit commented 3 years ago

Hi,

I'm trying to use schedy with template binary_sensor (holds information if cheaper electricity tariff is active based on time schedule). It works, but schedy does not return simple "on" / "off" states. It gives '["on"]' / '["off"]' states, so I have to use unusual checks like is_state(..., '[\"on\"]' instead of just 'on'. I've checked my configuration and documentation and it seems it could be bug?

Similar, when I add that entity into dashboard, it shows ["on"], or in rest api:

{'attributes': {'actor_wanted_values': {'binary_sensor.hdorcvr': '["on"]'},
                'overlay_active': False,
                'rescheduling_time': None,
                'scheduled_value': '["on"]'},
 'context': {'id': '7e0c4c3dedd3165ddf1ce5d559b16d1e',
             'parent_id': None,
             'user_id': 'fa72f846d2e44706b0db804cb2d9ec78'},
 'entity_id': 'schedy_room.schedy_hdo_wholehouse',
 'last_changed': '2021-01-15T12:45:35.942199+00:00',
 'last_updated': '2021-01-15T12:45:35.942199+00:00',
 'state': '["on"]'}

My configuration> apps/schedy_hdo.yaml

schedy_hdo:
  module: hass_apps_loader
  class: SchedyApp

  actor_type: switch
  schedule_append:
  - v: "off"

  rooms:
    wholehouse:
      allow_manual_changes: false
      actors:
        binary_sensor.hdorcvr:
      schedule:
      - v: "on"
        rules:
        - weekdays: 1-5
          rules:
          - { start: "04:00", end: "06:30" }
          - { start: "14:00", end: "18:30" }
          - { start: "20:00", end: "22:30" }
        - weekdays: 6-7
          rules:
          - { start: "08:00", end: "23:30" }

configuration sensor part>

binary_sensor:
  - platform: template
    sensors:
      hdorcvr:
        friendly_name: "HDO receiver"
        unique_id: hdorcvr
        device_class: power
        value_template: "{{ is_state('schedy_room.schedy_hdo_wholehouse', '[\"on\"]') }}"
bob1de commented 3 years ago

Hi,

That's no bug so far. The generic2 actor type (or switch, which is just a preconfigured generic2) works with lists internally, and you normally shouldn't deal with the schedy_room entities directly.

The problem here is that you seem to have a wrong notion of actors. A binary sensor can't be an actor. An actor is something Schedy controls. In case of the switch type, it needs to be something that's controllable by the homeassistant.turn_on/turn_off services, so you could use an input_boolean instead and drop the template sensor part altogether. Then, the input_boolean will be switched on and off according to your schedule and you can react to it as you like.

Closing this as it's not a bug. Feel free to keep commenting if something is still unclear.

Best regards Robert

mihlit commented 3 years ago

So, state is for internal use only, it is not supported and should not be used?

I know it's not exactly correct solution but it works :) I did not find any solution I liked as I want to show state in dashboard. If I add schedy state to dashboard it shows '["on"]' which does not look nice. I can't use input_* as it can't be made read-only in dashboard and it would not make sense from UIX perspective. Previously I had it wrapped with hidden input_boolean and template sensor that shows it, but was wondering if I can do it with two items instead of three.