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

How to send sensor state with an automation (service: modbus.write_register)

$
0
0

@Bard wrote:

Hi all,
i’m trying to send order through modbus service to an equipment.
This equipment accept only write done with function 16 and in order to satisfy this requirement I must send at least 2 registers with an array.
So I created an input_boolean in order to trigger an automation and with static value is working fine:

 - alias: OnOffCtrlNilan
  trigger:
    - platform: state
      entity_id: input_boolean.accensione_nilan
      to: 'on'
  condition: []
  action:
    service: modbus.write_register
    data:
      hub: Com1
      unit: 4
      address: 1001
    data_template:
      value: [1,2,2]

Now in order to send a single “order” I’m trying to send in the second register the value of the register itself that I’m already reading with a modbus sensor entity.
I wrote the following code:

- alias: OnOffCtrlNilan
  trigger:
    - platform: state
      entity_id: input_boolean.accensione_nilan
      to: 'on'
  condition: []
  action:
    service: modbus.write_register
    data:
      hub: Com1
      unit: 4
      address: 1001
    data_template:
      value: [1,{{ states('sensor.ctrlmode')|int }},2]

but I receive this error: invalid key: “OrderedDict([(“states(‘sensor.ctrlmode’)|int”, None)])”

I checked from the developer tools the state of the sensor and it is:
image

Could you help me?
Thanks in advance
Matteo

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 95513

Trending Articles



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