How to get something to execute on context entry

I have been looking at his problem for too long and am sure I am missing the obvious answer.

(Asterisk 11.4 on Fedora)

I want to set some CDR variables with info about all outgoing calls.

in sip.conf
context = context1

in extensions.conf

exten => s,1,SET(CDR(var1)=localdial)
exten => s,n,SET(CDR(var2)=device1)
exten => 800,1,Dial(SIP/Someextension)
include anothercontext

exten => s,1,SET(CDR(var1)=pstndial)
exten => _XXXXXXX, 1, Dial(SIP/blabla/${EXTEN})

The objective is when [Device] dials a number the CDR value is set correctly so it must set Var1 to localdial as it traverses Context1, but then change Var1 to pstndial when (and if) it has to go there to dial out. var2 would be set and remain set to identify the calling device.

What is the recommended way to do this? All suggestions appreciated. Thank you.

<NOTE this was posted on “General” (apparently the wrong forum) so posting here. Answer on General does not work (i.e. replacing s in context1 with _X.) 800 matches better so _X. is executed after the dial meaning never.

Result of dialplan show 800@context1:
‘800 => 1. Dial(SIP/800) [pbx_config]
’_X.’ => 1. Set(CDR(var1)=“localdial”) [pbx_config]
2. Set(CDR(var2)=“device1”) [pbx_config]