Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 106189

Using response_var from script to populate attribute of templated triggered binary sensors

$
0
0

I use a script to (successfully) get LLDP data from OpenWrt devices via Ubus, and want to make that data available to templates further down the line, so I’m attempting to create some templated entities with the LLDP data as attribute.

Passing the data from the script I get an error (full below), that would seem to indicate, that I should pass a dictionary, so I changed the relevant line from
lldp: {{ (lldp.stdout | from_json).lldp.interface ))
to:

alias: Get LLDP from OpenWrt
sequence:
  - data:
      subsystem: file
      method: exec
      parameters:
        command: /usr/sbin/lldpctl
        params:
          - "-f"
          - json
    response_variable: lldp
    target:
      entity_id: "{{ target }}"
    action: openwrt.ubus
  - variables:
      lldp: >
        {{ dict({}, interface=(lldp.stdout | from_json).lldp.interface ) }}
  - stop: End
    response_variable: lldp
mode: parallel
fields:
  target:
    selector:
      entity: {}
    name: Target OpenWrt Entity
    required: true

, but I still get the error
Get LLDP from OpenWrt: Error executing script. Error for call_service at pos 1: Failed to process the returned action response data, expected a dictionary, but got <class 'NoneType'>

and then again, the same error with a different prefix:
Trigger Update Coordinator: Error executing script. Error for call_service at pos 3:

When I run this script separately in developer tools, the output sure does look like a valid dictionary with my wanted LLDP data.

The whole context this is happening in:

  template:
    - trigger:
        platform: time_pattern
        minutes: "/1"
      action:
        - service: script.get_lldp_from_openwrt
          data:
            target: binary_sensor.openwrt_wrsw
          response_variable: lldp_wrsw
# Several more service calls like the above with different hostnames (wrsw = workroom switch)
      binary_sensor:
        - name: OpenWrt WRSW UBUS LLDP Topo
          unique_id: openwrt_wrsw_ubus_lldp
          state: "{{ states('binary_sensor.openwrt_wrsw') }}"
          attributes:
            data: "{{ lldp_wrsw }}"
# Several more binary sensors for different Openwrt Devices

I had built a prototype of something with similar value-passing a year ago, and got it working back then in my throw-away scratchpad installation, but can’t figure out anymore how I did it back then.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 106189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>