Extract JSON value

Hi, I want to extract the value of createdDate from the following JSON:

[
	["4bcdf9f2-5563-3ce9-8868-331b7eb970f6", {
		"alarmTime": 0,
		"automationId": null,
		"createdDate": 1589581887631,
		"deferredAtTime": null,
		"deliveryType": null,
		"deviceName": null,
		"deviceSerialNumber": "G090U61090140CSU",
		"deviceType": "A32DOYMUN6DTXA",
		"extensibleAttribute": null,
		"geoLocationTriggerData": null,
		"id": "A32DOYMUN6DTXA-G090U61090140CSU-4bcdf9f2-5563-3ce9-8868-331b7eb970f6",
		"lastOccurrenceTimeInMilli": 0,
		"lastUpdatedDate": 0,
		"musicAlarmId": null,
		"musicEntity": null,
		"notificationIndex": "4bcdf9f2-5563-3ce9-8868-331b7eb970f6",
		"originalDate": null,
		"originalTime": null,
		"personProfile": null,
		"provider": null,
		"rRuleData": null,
		"recurrenceEligibility": false,
		"recurringPattern": null,
		"remainingTime": 1799000.0,
		"reminderAppLabel": null,
		"reminderLabel": null,
		"reminderSubLabel": null,
		"skillInfo": null,
		"snoozedToTime": null,
		"sound": {
			"displayName": "Simple Timer",
			"folder": null,
			"id": "system_alerts_melodic_02",
			"providerId": "ECHO",
			"sampleUrl": "https://s3.amazonaws.com/deeappservice.prod.notificationtones/system_alerts_melodic_02.mp3"
		},
		"status": "ON",
		"targetPersonProfiles": null,
		"timeZoneId": null,
		"timerLabel": null,
		"tmwNotificationProperties": null,
		"triggerTime": 0,
		"type": "Timer",
		"version": "2"
	}]
]

I have tried {{ state_attr('sensor.dressing_room_echo_timer', 'sorted_active')["createdDate"] }} in the template editor but no luck. Any ideas?

{{ state_attr('sensor.dressing_room_echo_timer', 'sorted_active')[0][1][createdDate] }}

Yeah, I just tried that before you responded. I get this error:

Error rendering template: UndefinedError: str object has no element 1

It’s a string that looks like JSON.

Ah of course ha. Ok, so do I need to do something like to_json first?

1 Like
{% set timer = state_attr('sensor.dressing_room_echo_timer', 'sorted_active') | from_json %}
{{ timer[0][1]["createdDate"] }}