My first post. Until now I’ve got quite good help by reading others posts in this forum but now I’m lost.
The problem is that I need to get info from Trafikverket.se and they only accepts XML-queries. They can, however, send the answer in JSON.
I’ve been stuck now during my xmas-vacation and I would really like som help.
- platform: command_line
name: mayas_tag
command: "curl -kX POST https://api.trafikinfo.trafikverket.se/v2/data.json -H 'accept: application/json' -H 'Content-Type: application/xml' -d \"<REQUEST><LOGIN authenticationkey='d8655420528e4e1a803009fb414e4c2b' /><QUERY objecttype='TrainAnnouncement' schemaversion='1.8' orderby='AdvertisedTimeAtLocation'><FILTER><AND><EQ name='ActivityType' value='Avgang' /><EQ name='LocationSignature' value='Nä' /><EQ name='AdvertisedTrainIdent' value='7503' /><OR><AND><GT name='AdvertisedTimeAtLocation' value='$dateadd(-00:15:00)' /><LT name='AdvertisedTimeAtLocation' value='$dateadd(14:00:00)' /></AND><AND><LT name='AdvertisedTimeAtLocation' value='$dateadd(00:30:00)' /><GT name='EstimatedTimeAtLocation' value='$dateadd(-00:15:00)' /></AND></OR></AND></FILTER><INCLUDE>AdvertisedTrainIdent</INCLUDE><INCLUDE>AdvertisedTimeAtLocation</INCLUDE><INCLUDE>EstimatedTimeAtLocation</INCLUDE><INCLUDE>EstimatedTimeIsPreliminary</INCLUDE><INCLUDE>Canceled</INCLUDE></QUERY></REQUEST>\""
value_template: "{{ value_json['TrainAnnouncement']['TrainAnnouncement[0]'] }}"
json_attributes:
- AdvertisedTimeAtLocation
- AdvertisedTrainIdent
- Canceled
- EstimatedTimeIsPreliminary
scan_interval: 600
My very long curl is what I think should be written/transformed from
<REQUEST>
<LOGIN authenticationkey="openapiconsolekey" />
<QUERY objecttype="TrainAnnouncement" schemaversion="1.8" orderby="AdvertisedTimeAtLocation">
<FILTER>
<AND>
<EQ name="ActivityType" value="Avgang" />
<EQ name="LocationSignature" value="Nä" />
<EQ name="AdvertisedTrainIdent" value="7503" />
<OR>
<AND>
<GT name="AdvertisedTimeAtLocation" value="$dateadd(-00:15:00)" />
<LT name="AdvertisedTimeAtLocation" value="$dateadd(14:00:00)" />
</AND>
<AND>
<LT name="AdvertisedTimeAtLocation" value="$dateadd(00:30:00)" />
<GT name="EstimatedTimeAtLocation" value="$dateadd(-00:15:00)" />
</AND>
</OR>
</AND>
</FILTER>
<INCLUDE>AdvertisedTrainIdent</INCLUDE>
<INCLUDE>AdvertisedTimeAtLocation</INCLUDE>
<INCLUDE>EstimatedTimeAtLocation</INCLUDE>
<INCLUDE>EstimatedTimeIsPreliminary</INCLUDE>
<INCLUDE>Canceled</INCLUDE>
</QUERY>
</REQUEST>
After restarting I finaly got this error
Logger: homeassistant.components.command_line.sensor
Source: components/command_line/sensor.py:122
Integration: command_line (documentation, issues)
First occurred: 00:44:25 (1 occurrences)
Last logged: 00:44:25
Empty reply found when expecting JSON data