Hi everyone. I have the feeling this is a very basic question, but after hours on Google and the forum, I’m unable to find a solution and hope someone can help or at least point me in the right direction/documentation.
I have setup HA, which is properly receiving data from an eBus via the MQTT integration. Now I would like to push some information to a PRTG monitor server, which I can already do with a rest_command, and is working.
To do this, I defined the rest_command in my configuration.yaml
rest_command:
prtg:
url: https://xxx.xxx/some_id
method: POST
headers:
accept: 'application/json, text/html'
payload: '{"prtg":{"result":[{"channel":"{{ sensor_name }}","value":"{{ value }}"}]}}'
content_type: 'application/json; charset=utf-8'
verify_ssl: false
and I define the trigger in automations.yaml:
- alias: Push Value to PRTG
trigger:
- entity_id: sensor.ebusd_hmu_state_energy
platform: state
action:
service: rest_command.prtg
data_template:
sensor_name: Compressor Modulation
value: '{{ states("sensor.ebusd_hmu_state_energy") | int }}'
id: ba170497e97b4e138d9fdd4ceca8eb80
This all works fine. Now I would like to add also the status of the compressor to this rest_command. This status gets reported in HA as a text (for example ‘frost_protection’, or ‘standby’), and to send it to PRTG I need to convert these codes back to their number. I have the (long) list for the conversion, but don’t know how to do this in the YAML.
The sensor I need to use for this is called ebusd_hmu_rundatastatuscode, and the conversion list looks like this (about 50 entries):
{ 34: 'Frost_protection' },
{ 100: 'Standby' },
{ 101: 'Heating_Compressor_shutdown' },
{ 102: 'Heating_Compressor_blocked' },
{ 103: 'Heating_Prerun' },
{ 104: 'Heating_Compressor_active' },
{ 107: 'Heating_Overrun' },
{ 111: 'Cooling_Compressor_shutdown' },
{ 112: 'Cooling_Compressor_blocked' },
{ 113: 'Cooling_Prerun' },
...
To add this extra information, I’m assuming I need to update the part in automations.yaml to the following:
- alias: Push Value to PRTG
trigger:
- entity_id: sensor.ebusd_hmu_state_energy
platform: state
- entity_id: sensor.ebusd_hmu_rundatastatuscode
platform: state
action:
service: rest_command.prtg
data_template:
- sensor_name: Compressor Modulation
value: '{{ states("sensor.ebusd_hmu_state_energy") | int }}'
- sensor_name: Compressor Status
value: --What to put here to convert the text to the correct number for the status?--
id: ba170497e97b4e138d9fdd4ceca8eb80
My question is what to put in the value attribute of that new sensor in the code above?
Edit: in addition to my previous question, I figured out that my ‘assumed’ new part in automations.yaml will not work, as the rest_command.prtg expects only 1 channel/value pair in the payload. Adding the 2 sensor names and results in the action will not work. What would be an elegant way to define the rest_command.prtg so it would take all channel/value pairs in it’s value? Can I write a loop in the definition of the payload field of the rest_command.prtg to include all present channel/value pairs? If so, could someone help me how I would do that? (Let me know if I should create a seperate topic for this?)
Can anyone help?
Thank you in advance,
Wim