Transform API output to items

Now I have an issue to Jsonpath for the respons from my KIA api, Json validates in some json validators but fails in jsonpath validators. Could anyone point me into the right direction for jsonpath or any other solution?

String Item whre I would like to catch value 130 for _ev_estimated_station_charge_duration_value=130, andI assuem the first string in ‘’ is a uid for that car and if I had multiple cars I also need a filter for just that uid.

EV_estimated_charging.postUpdate(transform("JSONPATH", "$.e238a624-1aa3-4d40-bed4-5fe3fcc9fde2.Vehicle._ev_estimated_station_charge_duration", json))

Response string or json or however to handle it
Kia json.txt (6.8 KB)

Samplecode from txt file

Item 'EV_estimated_charging' changed from {'e238a624-1aa3-4d40-bed4-5fe3fcc9fde2': Vehicle(id='e238a624-1aa3-4d40-bed4-5fe3fcc9fde2', name='E-SOUL', model='E-SOUL', registration_date='2021-02-27 11:28:11.022', year=None, VIN=None, key=None, _total_driving_distance=154, _total_driving_distance_value=154, _total_driving_distance_unit='km', _odometer=21124.6, _odometer_value=21124.6, _odometer_unit='km', car_battery_percentage=99, engine_is_running=False, last_updated_at=datetime.datetime(2022, 9, 7, 18, 5, 40, tzinfo=tzfile('/usr/share/zoneinfo/Europe/Berlin')), smart_key_battery_warning_is_on=None, washer_fluid_warning_is_on=None, brake_fluid_warning_is_on=None, _air_temperature='02H', _air_temperature_value='02H', _air_temperature_unit='°C', air_control_is_on=False, defrost_is_on=False, steering_wheel_heater_is_on=0, back_window_heater_is_on=0, side_mirror_heater_is_on=None, front_left_seat_status=None, front_right_seat_status=None, rear_left_seat_status=None, rear_right_seat_status=None, is_locked=False, front_left_door_is_open=0, front_right_door_is_open=0, back_left_door_is_open=0, back_right_door_is_open=0, trunk_is_open=False, hood_is_open=None, tire_pressure_all_warning_is_on=None, tire_pressure_rear_left_warning_is_on=None, tire_pressure_front_left_warning_is_on=None, tire_pressure_front_right_warning_is_on=None, tire_pressure_rear_right_warning_is_on=None, _next_service_distance=None, _next_service_distance_value=None, _next_service_distance_unit=None, _last_service_distance=None, _last_service_distance_value=None, _last_service_distance_unit=None, _location_latitude=58.541603, _location_longitude=15.059267, _location_last_set_time=datetime.datetime(2022, 9, 7, 20, 5, 7, tzinfo=tzfile('/usr/share/zoneinfo/Europe/Berlin')), ev_battery_percentage=58, ev_battery_is_charging=False, ev_battery_is_plugged_in=0, _ev_driving_distance=154, _ev_driving_distance_value=154, _ev_driving_distance_unit='km', _ev_estimated_current_charge_duration=0, _ev_estimated_current_charge_duration_value=0, _ev_estimated_current_charge_duration_unit='m', _ev_estimated_fast_charge_duration=74, _ev_estimated_fast_charge_duration_value=74, _ev_estimated_fast_charge_duration_unit='m', _ev_estimated_portable_charge_duration=600, _ev_estimated_portable_charge_duration_value=600, _ev_estimated_portable_charge_duration_unit='m', _ev_estimated_station_charge_duration=130, _ev_estimated_station_charge_duration_value=130, _ev_estimated_station_charge_duration_unit='m', _ev_charge_limits=EvChargeLimits(ac=0, dc=0), _fuel_driving_distance=None, _fuel_driving_distance_value=None, _fuel_driving_distance_unit=None, fuel_level=None, fuel_l

As best as I can tell that isn’t valid JSON. That’s why only the last half of it is “pretty printed” with proper spacing and indentations.

You don’t use ( ) to specify elements in JSON. You use { } to denote dict. You use [ ] to denote an array. Furthermore, you use “:” to separate a key from it’s value, not “=”. So as far as I can tell, from a JSON perspective, you have one key: “e238a624-1aa3-4d40-bed4-5fe3fcc9fde2” and the whole rest of the document is a single value and that single value is a mix of JSON and ???.

In short, you’re not going to be able to use JSONPATH for this. You might be able to get something to work using REGEX or a custom parser in a rule.

1 Like

Have you played around with Postman? I have used that to help me determine the right values before. I would try to verify functionality before trying to bring it into OH.

You could use the JS transformation and use your custom script manipulate data before putting it into jasonpath transformation. Then you only need one custom script.

image

Hi all

It seems like I got two new ideas to test and two new mountains to climb, but if one reach the top you feel better. I will look into this options and se if it’s within my capacity to get it done.

Good morning

I’m trying to fiddle around with this thing again, I have no clue about JS tranformation but I-ve been messing with texteditors to just find the correct structure.

If I could get a hint of how to remove everything before <‘vehicleLocation’: {> and maybe a hint of of to replace chars wit js transformation the it will be ok.

I have looked into the python script generating the output but it’s not that starigtforward as one would hope.

Cheers /Marcus

It’s just javascript, with all the tutorials of the web to support it.

In the OH transformation usage, you get one string as input and will return just one string.

If you’re fumbling a bit with programming, you might find it easier to work in a rule instead - much easier to edit and debug. And for a bonus you may update multiple different Items from one rule.