Rest command send state in url

I’m trying send link like this
http://dane.pvmonitor.pl/pv/get2.php?idl=11107&p=xxxxxxxxNu7G&F4.3=27.988
the begining is always the same: http://dane.pvmonitor.pl/pv/get2.php?idl=11107&p=xxxxxxxxNu7G
I’m trying to use rest command to sent data, but with no luck

rest_command:
  pvmonitor:
    url: http://dane.pvmonitor.pl/pv/get2.php?idl=11107&p=xxxxxxxxNu7G{{pvm}}
    method: GET
{
  'pvm': '&F4.3={{states("sensor.salon_energia")}}'
}

and I’m getting:

Apr 04 15:36:57 HomeAssistant hass[252]: 2020-04-04 15:36:57 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=rest_command, service=pvmonitor, service_data=pvm=&F4.3={{ states.sensor.salon_energia }}>
Apr 04 15:36:58 HomeAssistant hass[252]: 2020-04-04 15:36:58 DEBUG (MainThread) [homeassistant.components.rest_command] Success. Url: http://dane.pvmonitor.pl/pv/get2.php?idl=11107&p=xxxxxxxxNu7G&F4.3=%7B%7B+states.sensor.salon_energia+%7D%7D. Status code: 200.

any idea how to fix it?

Try quotes. They are needed for ALL single line templates.

url: "http://dane.pvmonitor.pl/pv/get2.php?idl=11107&p=xxxxxxxxNu7G{{pvm}}"

It didn’t helped.
The result is the same.

Oh, duh, sorry. That is only step one.

What is {{pvm}}? Where is it defined? Are you passing it into this command as a data thing? Why are you trying to pass the state to parse and not just the value? Oh, you’re probably trying from the developer tools? You should know, the developer tools often doesn’t use templates. So if you’re calling

Service: 
  rest_command.pvmonitor
Service Data
  pvm: &F4.3={{states('sensor.salon_energia')}}

It wont evaluate the template for you. Just try putting in a real value for it to test.

Service: 
  rest_command.pvmonitor
Service Data
  pvm: &F4.3=27.988

If that works, you can use it with templates in normal automations/scripts/etc.

But you’ll still need the quotes around the url.

With real values it’s working perfectly.
{{pvm}} is in url i rest_command:

rest_command:
  pvmonitor:
    url: "http://dane.pvmonitor.pl/pv/get2.php?idl=11107&p=xxxxxxxxNu7G{{pvm}}"
    method: GET

Yes, I try it in developer tools, and after your reply I tested it with Automation, but with no luck.
Debug output from log:

Apr 04 18:26:09 HomeAssistant hass[252]: 2020-04-04 18:26:09 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=rest_command, service=pvmonitor, service_data=pvm=&F4.3={{states("sensor.salon_energia")}}>
Apr 04 18:26:09 HomeAssistant hass[252]: 2020-04-04 18:26:09 DEBUG (MainThread) [homeassistant.components.rest_command] Success. Url: http://dane.pvmonitor.pl/pv/get2.php?idl=11107&p=xxxxxxxxNu7G&F4.3=%7B%7Bstates(%22sensor.salon_energia%22)%7D%7D. Status code: 200.

What are you using to call this rest_command?

If it’s an automation then does its action look something like this?

  action:
    - service: rest_command.pvmonitor
      data_template:
        pvm: '&F4.3={{states("sensor.salon_energia")}}'

EDIT
I don’t have experience using a rest_command so I’m making an assumption that the variable being passed (pvm) is allowed to have a template.

My automation:

- id: '1585593257936'
  alias: PVmonitor
  description: ''
  trigger:
  - entity_id: sensor.salon_energia
    platform: state
  condition: []
  action:
  - data:
      pvm: '&F4.3={{states("sensor.salon_energia")}}'
    service: rest_command.pvmonitor

Problem resolved, thank you for your help. data_template solved the problem

1 Like

Non English replies removed. Please read point 0 here.