I have made a Tasker profile. It works by waiting for a state change and then reverting the screen state to whatever it was before said change.
Here is the copy of my Screen.prj.xml
profile:
<TaskerData sr="" dvi="1" tv="6.0.10">
<Profile sr="prof42" ve="2">
<cdate>1658764422437</cdate>
<edate>1658770109384</edate>
<flags>8</flags>
<id>42</id>
<mid0>41</mid0>
<nme>POWER UNPLUGGED</nme>
<Share sr="Share">
<b>false</b>
<d>When you unplug your phone from a power source, have your screen automatically lock itself.</d>
<g>Basics,Display,Security</g>
<p>true</p>
<t></t>
</Share>
<State sr="con0" ve="2">
<code>10</code>
<pin>true</pin>
<Int sr="arg0" val="0"/>
</State>
</Profile>
<Profile sr="prof47" ve="2">
<cdate>1658765139741</cdate>
<clp>true</clp>
<edate>1658770063039</edate>
<flags>8</flags>
<id>47</id>
<mid0>48</mid0>
<nme>DISP ON</nme>
<Event sr="con0" ve="2">
<code>208</code>
</Event>
</Profile>
<Profile sr="prof49" ve="2">
<cdate>1658765984104</cdate>
<clp>true</clp>
<edate>1658770076363</edate>
<flags>8</flags>
<id>49</id>
<mid0>50</mid0>
<nme>DISP OFF</nme>
<Event sr="con0" ve="2">
<code>210</code>
</Event>
</Profile>
<Profile sr="prof51" ve="2">
<cdate>1658764422437</cdate>
<clp>true</clp>
<edate>1658770092328</edate>
<flags>8</flags>
<id>51</id>
<mid0>52</mid0>
<nme>POWER PLUGGED</nme>
<Share sr="Share">
<b>false</b>
<d>When you plug your phone in leave screen on/off state alone. (Will revert screen state after android toggles it).</d>
<g>Display,Power</g>
<p>true</p>
<t></t>
</Share>
<State sr="con0" ve="2">
<code>10</code>
<Int sr="arg0" val="0"/>
</State>
</Profile>
<Project sr="proj0" ve="2">
<cdate>1658764409345</cdate>
<name>SCREEN</name>
<pids>47,42,49,51</pids>
<tids>46,50,41,48,52</tids>
<Share sr="Share">
<b>false</b>
<d>Revert or maintain screen on/off state after power plugged in or out.</d>
<g>Display,Power</g>
<p>true</p>
<t></t>
</Share>
</Project>
<Task sr="task41">
<cdate>1650476952536</cdate>
<edate>1658769236054</edate>
<id>41</id>
<pri>100</pri>
<Action sr="act0" ve="7">
<code>547</code>
<Str sr="arg0" ve="3">%STARTED</Str>
<Str sr="arg1" ve="3">%TIMES</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
<Int sr="arg4" val="0"/>
<Int sr="arg5" val="3"/>
<Int sr="arg6" val="1"/>
<ConditionList sr="if">
<bool0>And</bool0>
<Condition sr="c0" ve="3">
<lhs>%STARTED</lhs>
<op>13</op>
<rhs></rhs>
</Condition>
<Condition sr="c1" ve="3">
<lhs>%SCREEN</lhs>
<op>2</op>
<rhs>on</rhs>
</Condition>
</ConditionList>
</Action>
<Action sr="act1" ve="7">
<code>547</code>
<Str sr="arg0" ve="3">%UPTIME</Str>
<Str sr="arg1" ve="3">%TIMES-%STARTED</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="1"/>
<Int sr="arg4" val="0"/>
<Int sr="arg5" val="3"/>
<Int sr="arg6" val="1"/>
</Action>
<Action sr="act2" ve="7">
<code>548</code>
<on>false</on>
<Str sr="arg0" ve="3">%UPTIME</Str>
<Int sr="arg1" val="0"/>
<Str sr="arg10" ve="3"/>
<Int sr="arg11" val="1"/>
<Int sr="arg12" val="0"/>
<Str sr="arg13" ve="3"/>
<Int sr="arg14" val="0"/>
<Int sr="arg2" val="0"/>
<Str sr="arg3" ve="3"/>
<Str sr="arg4" ve="3"/>
<Str sr="arg5" ve="3"/>
<Str sr="arg6" ve="3"/>
<Str sr="arg7" ve="3"/>
<Str sr="arg8" ve="3"/>
<Int sr="arg9" val="1"/>
</Action>
<Action sr="act3" ve="7">
<code>248</code>
<Int sr="arg0" val="0"/>
<Int sr="arg1" val="1"/>
<ConditionList sr="if">
<Condition sr="c0" ve="3">
<lhs>%UPTIME</lhs>
<op>6</op>
<rhs>1</rhs>
</Condition>
</ConditionList>
</Action>
</Task>
<Task sr="task46">
<cdate>1658764707914</cdate>
<edate>1658765118823</edate>
<id>46</id>
<nme>Dont Screen On On Power</nme>
<Action sr="act0" ve="7">
<code>548</code>
<Str sr="arg0" ve="3">%SCREEN</Str>
<Int sr="arg1" val="0"/>
<Str sr="arg10" ve="3"/>
<Int sr="arg11" val="1"/>
<Int sr="arg12" val="0"/>
<Str sr="arg13" ve="3"/>
<Int sr="arg14" val="0"/>
<Int sr="arg2" val="0"/>
<Str sr="arg3" ve="3"/>
<Str sr="arg4" ve="3"/>
<Str sr="arg5" ve="3"/>
<Str sr="arg6" ve="3"/>
<Str sr="arg7" ve="3"/>
<Str sr="arg8" ve="3"/>
<Int sr="arg9" val="1"/>
</Action>
<Action sr="act1" ve="7">
<code>248</code>
<on>false</on>
<Int sr="arg0" val="0"/>
<Int sr="arg1" val="0"/>
<ConditionList sr="if">
<Condition sr="c0" ve="3">
<lhs>%SCREEN</lhs>
<op>2</op>
<rhs>off</rhs>
</Condition>
</ConditionList>
</Action>
</Task>
<Task sr="task48">
<cdate>1658765152954</cdate>
<edate>1658767756538</edate>
<id>48</id>
<nme>Display Uptime</nme>
<pri>6</pri>
<Action sr="act0" ve="7">
<code>547</code>
<Str sr="arg0" ve="3">%STARTED</Str>
<Str sr="arg1" ve="3">%TIMES</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
<Int sr="arg4" val="0"/>
<Int sr="arg5" val="3"/>
<Int sr="arg6" val="1"/>
</Action>
<Action sr="act1" ve="7">
<code>548</code>
<on>false</on>
<Str sr="arg0" ve="3">started %STARTED</Str>
<Int sr="arg1" val="0"/>
<Str sr="arg10" ve="3"/>
<Int sr="arg11" val="1"/>
<Int sr="arg12" val="0"/>
<Str sr="arg13" ve="3"/>
<Int sr="arg14" val="0"/>
<Int sr="arg2" val="0"/>
<Str sr="arg3" ve="3"/>
<Str sr="arg4" ve="3"/>
<Str sr="arg5" ve="3"/>
<Str sr="arg6" ve="3"/>
<Str sr="arg7" ve="3"/>
<Str sr="arg8" ve="3"/>
<Int sr="arg9" val="1"/>
</Action>
<Action sr="act2" ve="7">
<code>549</code>
<Str sr="arg0" ve="3">%STOPPED</Str>
<Int sr="arg1" val="0"/>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
</Action>
</Task>
<Task sr="task50">
<cdate>1658766071199</cdate>
<edate>1658769148172</edate>
<id>50</id>
<nme>Reset Screen Uptime</nme>
<pri>6</pri>
<Action sr="act0" ve="7">
<code>547</code>
<Str sr="arg0" ve="3">%STOPPED</Str>
<Str sr="arg1" ve="3">%TIMES</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
<Int sr="arg4" val="0"/>
<Int sr="arg5" val="3"/>
<Int sr="arg6" val="1"/>
</Action>
<Action sr="act1" ve="7">
<code>548</code>
<on>false</on>
<Str sr="arg0" ve="3">Stopped %STOPPED</Str>
<Int sr="arg1" val="0"/>
<Str sr="arg10" ve="3"/>
<Int sr="arg11" val="1"/>
<Int sr="arg12" val="0"/>
<Str sr="arg13" ve="3"/>
<Int sr="arg14" val="0"/>
<Int sr="arg2" val="0"/>
<Str sr="arg3" ve="3"/>
<Str sr="arg4" ve="3"/>
<Str sr="arg5" ve="3"/>
<Str sr="arg6" ve="3"/>
<Str sr="arg7" ve="3"/>
<Str sr="arg8" ve="3"/>
<Int sr="arg9" val="1"/>
</Action>
<Action sr="act2" ve="7">
<code>547</code>
<on>false</on>
<Str sr="arg0" ve="3">%UPTIME</Str>
<Str sr="arg1" ve="3">0</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
<Int sr="arg4" val="0"/>
<Int sr="arg5" val="3"/>
<Int sr="arg6" val="1"/>
</Action>
<Action sr="act3" ve="7">
<code>549</code>
<Str sr="arg0" ve="3">%STARTED</Str>
<Int sr="arg1" val="0"/>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
</Action>
</Task>
<Task sr="task52">
<cdate>1650476952536</cdate>
<edate>1658769822832</edate>
<id>52</id>
<pri>100</pri>
<Action sr="act0" ve="7">
<code>548</code>
<on>false</on>
<Str sr="arg0" ve="3">%STOPPED</Str>
<Int sr="arg1" val="0"/>
<Str sr="arg10" ve="3"/>
<Int sr="arg11" val="1"/>
<Int sr="arg12" val="0"/>
<Str sr="arg13" ve="3"/>
<Int sr="arg14" val="0"/>
<Int sr="arg2" val="0"/>
<Str sr="arg3" ve="3"/>
<Str sr="arg4" ve="3"/>
<Str sr="arg5" ve="3"/>
<Str sr="arg6" ve="3"/>
<Str sr="arg7" ve="3"/>
<Str sr="arg8" ve="3"/>
<Int sr="arg9" val="1"/>
</Action>
<Action sr="act1" ve="7">
<code>547</code>
<on>false</on>
<Str sr="arg0" ve="3">%STOPPED</Str>
<Str sr="arg1" ve="3">%TIMES</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
<Int sr="arg4" val="0"/>
<Int sr="arg5" val="3"/>
<Int sr="arg6" val="1"/>
<ConditionList sr="if">
<bool0>And</bool0>
<Condition sr="c0" ve="3">
<lhs>%STOPPED</lhs>
<op>13</op>
<rhs></rhs>
</Condition>
<Condition sr="c1" ve="3">
<lhs>%SCREEN</lhs>
<op>2</op>
<rhs>off</rhs>
</Condition>
</ConditionList>
</Action>
<Action sr="act2" ve="7">
<code>547</code>
<Str sr="arg0" ve="3">%DOWNTIME</Str>
<Str sr="arg1" ve="3">%TIMES-%STOPPED</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="1"/>
<Int sr="arg4" val="0"/>
<Int sr="arg5" val="3"/>
<Int sr="arg6" val="1"/>
</Action>
<Action sr="act3" ve="7">
<code>547</code>
<Str sr="arg0" ve="3">%DOWNTIME</Str>
<Str sr="arg1" ve="3">0</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
<Int sr="arg4" val="0"/>
<Int sr="arg5" val="3"/>
<Int sr="arg6" val="1"/>
<ConditionList sr="if">
<Condition sr="c0" ve="3">
<lhs>%STOPPED</lhs>
<op>13</op>
<rhs></rhs>
</Condition>
</ConditionList>
</Action>
<Action sr="act4" ve="7">
<code>548</code>
<on>false</on>
<Str sr="arg0" ve="3">Downtime %DOWNTIME</Str>
<Int sr="arg1" val="0"/>
<Str sr="arg10" ve="3"/>
<Int sr="arg11" val="1"/>
<Int sr="arg12" val="0"/>
<Str sr="arg13" ve="3"/>
<Int sr="arg14" val="0"/>
<Int sr="arg2" val="0"/>
<Str sr="arg3" ve="3"/>
<Str sr="arg4" ve="3"/>
<Str sr="arg5" ve="3"/>
<Str sr="arg6" ve="3"/>
<Str sr="arg7" ve="3"/>
<Str sr="arg8" ve="3"/>
<Int sr="arg9" val="1"/>
</Action>
<Action sr="act5" ve="7">
<code>806</code>
<on>false</on>
<Int sr="arg0" val="216"/>
<ConditionList sr="if">
<Condition sr="c0" ve="3">
<lhs>%DOWNTIME</lhs>
<op>6</op>
<rhs>2</rhs>
</Condition>
</ConditionList>
</Action>
<Action sr="act6" ve="7">
<code>248</code>
<Int sr="arg0" val="1"/>
<Int sr="arg1" val="1"/>
<ConditionList sr="if">
<Condition sr="c0" ve="3">
<lhs>%DOWNTIME</lhs>
<op>7</op>
<rhs>1</rhs>
</Condition>
</ConditionList>
</Action>
<Action sr="act7" ve="7">
<code>548</code>
<on>false</on>
<Str sr="arg0" ve="3">%DOWNTIME</Str>
<Int sr="arg1" val="0"/>
<Str sr="arg10" ve="3"/>
<Int sr="arg11" val="1"/>
<Int sr="arg12" val="0"/>
<Str sr="arg13" ve="3"/>
<Int sr="arg14" val="0"/>
<Int sr="arg2" val="0"/>
<Str sr="arg3" ve="3"/>
<Str sr="arg4" ve="3"/>
<Str sr="arg5" ve="3"/>
<Str sr="arg6" ve="3"/>
<Str sr="arg7" ve="3"/>
<Str sr="arg8" ve="3"/>
<Int sr="arg9" val="1"/>
</Action>
</Task>
</TaskerData>