bhyve-home-assistant icon indicating copy to clipboard operation
bhyve-home-assistant copied to clipboard

using templates in start_watering service call

Open precbioinf opened this issue 3 years ago • 2 comments

Describe the bug I am attempting to call bhyve.start_watering with minutes specified by a template:

- type: button
  tap_action:
    action: call-service
    service: bhyve.start_watering
    service_data:
      entity_id: switch.backyard_zone
      minutes: '{{ states("input_number.watering_time") | int }}'

But it reports "expected int for dictionary value @ data['minutes']"

The "input_number.watering_time" is correctly set. In Developer Tools, template editor, the same {{...}} reports the correct value.

timer is {{ states("input_number.watering_time") | int }} shows: timer is 6

Logs

Logger: homeassistant.components.websocket_api.http.connection
Source: core.py:1399
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 3:54:30 PM (2 occurrences)
Last logged: 3:54:41 PM

[2928512784] expected int for dictionary value @ data['minutes']

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 135, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1399, in async_call
    processed_data = handler.schema(service_data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
    return base_validate(path, iteritems(data), out)
  File "/usr/local/lib/python3.8/site-packages/voluptuous/schema_builder.py", line 432, in validate_mapping
    raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: required key not provided @ data['minutes']

I tried data_template instead of service_data, then it reports required key not provided @ data['entity_id']

precbioinf avatar Dec 30 '20 23:12 precbioinf

Good question... I can reproduce the same issue. I'll dig around, for now I think a viable workaround might be to use a script?

sebr avatar Jan 01 '21 10:01 sebr

not sure if it helps or not but I'm using a virtual switch and an automation to go around this. Automation listens for the virtual switch to turn on, then runs the watering cycle based on the time template and then resets the virtual switch to off.

trigger:
  - platform: state
    entity_id: input_boolean.virtual_switch
    to: 'on'
condition: []
action:
  - service: bhyve.start_watering
    data:
      entity_id: switch.zone
      minutes: '{{ states(''input_number.bhyve_run_time'') | int }}'
  - wait_template: '00:01:00'
  - service: input_boolean.turn_off
    target:
      entity_id: input_boolean.virtual_switch
mode: single

briodan avatar Jul 06 '21 00:07 briodan