SOLVED: Command_line command using curl

I have automation for my Home Energy Meter (HEM) energy events. The automation looks like:

automation 22:
  alias: 'HEM Energy Event'
  trigger:
    platform: state
    entity_id: sensor.hem_energy
  action:
    service: notify.EG

The service notify.EG looks like:

# ======================================================================
notify 2:
  name: EG
  platform: command_line
  command: 'curl http://192.168.1.231:88/?Hem.energy&{{states.sensor.hem_energy}}'

The Ip address is that of my eventghost server which receives an event from the above hich looks like

HTTP.Hem.energy[]

This is incomplete.The actual energy value is not passed. No doubt due to the way I constructed the curl command.

Assume the value for sensor.hem_energy = 1000. If I were to enter this curl command from a terminal window it would look like:

curl "http://192.168.1.231:88/?Hem.energy&1000"

the EG server then would receive an event which looks like

HTTP.Hem.energy[u'1000']

What do I need to change within the command_line/command: to achiev this result?

After hours of frustration I was just ready to give up when I decided I would search the forum for “eventghost”. That brought up a post I made well over two years ago where one response suggested I use shell_command instead. Easy peasy :slight_smile: Here is what I ended up with

automation 22:
  alias: 'HEM Energy Event'
  trigger:
    platform: state
    entity_id: sensor.hem_energy
  action:
    service: shell_command.generic
    data_template:
      message: 'RaspPi.HEM.Energy.Event'
      state: '{{ states("sensor.hem_energy") }}'

shell_command:
  generic: curl "http://192.168.1.231:88/?{{message}}&{{state}}"

If GreenTurtwig is still around after all this time, THANK YOU!!!

FWIW, I believe the main issue with your first attempt was you used:

{{states.sensor.hem_energy}}

in your command instead of:

{{states.sensor.hem_energy.state}}

or

{{states("sensor.hem_energy")}}