I am new to home automation having installed it yesterday. Maybe my first effort is a bridge too far given my level of understanding. I want to do a REST GET and send the JSON to my MQTT broker. I think the code works to get the JSON but the broker does not get what I expected. Just in case my error is obvious to the most casual observer I will post it here. I put this code in in configuration.yaml
default_config:
frontend:
themes: !include_dir_merge_named themes
logger:
default: info
rest_command:
get_report_1:
url: "http://192.168.1.15:32000/Driver/Uranus/Report?DriverUniqueKey=606e7eca-4f45-4956-8faa-e3d0a4b694bd"
method: "get"
automation:
- alias: "Retrieve and Publish Report 1 to MQTT"
trigger:
- platform: time_pattern
seconds: 10 # Trigger every 10 seconds
action:
- service: rest_command.get_report_1
- service: mqtt.publish
data_template:
topic: "report_1"
payload_template: "{{ states('rest_command.get_report_1') }}"
# Assuming 'rest_command.get_report_1' returns a JSON string
- service: logger.log
data:
message: "Response: {{ states('rest_command.get_report_1') }}"
- service: python_script.parse_json_data
# Replace 'python_script.parse_json_data' with the correct service to process JSON data
python_script:
parse_json_data:
sequence:
- service: mqtt.publish
data_template:
topic: "parsed_data"
payload_template: "{{ states('rest_command.get_report_1') | from_json | json_query('data') }}"
and my rest call returns this:
{"status":"success","code":202,"message":"Report.","data":{"uniqueKey":"606e7eca-4f45-4956-8faa-e3d0a4b694bd","name":"Uranus","message":{"temperature":{"temperature":15.4,"messageType":"EnvironmentTemperature"},"relativeHumidity":{"percentage":18,"messageType":"Humidity"},"dewPoint":{"temperature":-8.8,"messageType":"EnvironmentTemperature"},"absolutePressure":{"hPa":823.21,"messageType":"Pressure"},"relativePressure":{"hPa":1020.83,"messageType":"Pressure"},"barometricAltitude":{"meters":1781,"messageType":"Elevation"},"skyQuality":{"mpsas":19.7,"messageType":"SkyQuality"},"nelm":{"vMag":5.29,"messageType":"NakedEyeLimitMagnitude"},"illuminance":{"lux":0.0086,"messageType":"Illuminance"},"temperatureDifference":{"temperature":35.9,"messageType":"EnvironmentTemperature"},"cloudCoverage":{"percentage":12,"messageType":"CloudCoverage"},"skyTemperature":{"temperature":-14.6,"messageType":"EnvironmentTemperature"},"isGpsFixed":true,"dateTime":"2023-11-07T04:40:37","latitude":{"dms":{"degree":35,"minute":11,"second":18.13,"standardFormat":"+35°11′18.13″","messageType":"DMS"},"dd":{"decimalDegree":35.18837,"messageType":"DD"},"messageType":"Latitude"},"longitude":{"dms":{"degree":-106,"minute":30,"second":54,"standardFormat":"-106°30′54.00″","messageType":"DMS"},"dd":{"decimalDegree":-106.515,"messageType":"DD"},"messageType":"Longitude"},"totalSatellites":9,"altitude":{"meters":1781,"messageType":"Elevation"},"messageType":"UranusAggregateReport"}}}
but my broker only gets messageType=UranusAggregate Report report_1= unknown
I would like to see what is going on but I can’t figure out how to debug this. Is there any guidance on how to debug these automations?
Thanks
Kurt