My complete flow is gigantic and involves lots of variables. Posting the complete flow will probably be confusing.
But this is the part you have seen:
[{"id":"a79d657b.d79498","type":"switch","z":"9f20b43d.4c5c78","name":"Is batterylevel above 90%?","property":"batterylevel","propertyType":"msg","rules":[{"t":"gte","v":"90","vt":"num"},{"t":"lt","v":"90","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":2900,"y":320,"wires":[["fb2484ba.c981a8"],["130d7cc9.841023"]]},{"id":"5ad20ac.96d24f4","type":"api-call-service","z":"9f20b43d.4c5c78","name":"Try to force update battery level","server":"4bbca37b.1700ec","version":1,"debugenabled":false,"service_domain":"homeassistant","service":"update_entity","entityId":"","data":"{\"entity_id\": msg.level}","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":2890,"y":460,"wires":[["16d45f28.ba78c1"]]},{"id":"fb2484ba.c981a8","type":"time-range-switch","z":"9f20b43d.4c5c78","name":"","lat":"","lon":"","startTime":"08:00","endTime":"20:00","startOffset":0,"endOffset":0,"x":3310,"y":340,"wires":[["40d79dce.353c14"],["d44a6fb0.8475a"]]},{"id":"16d45f28.ba78c1","type":"delay","z":"9f20b43d.4c5c78","name":"","pauseType":"delay","timeout":"30","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":2600,"y":540,"wires":[["9176519d.8853a"]]},{"id":"cbdfba21.c06818","type":"api-call-service","z":"9f20b43d.4c5c78","name":"Display the current batterylevel in Lovelace","server":"4bbca37b.1700ec","version":1,"debugenabled":false,"service_domain":"input_text","service":"set_value","entityId":"{{percent}}","data":"{\"entity_id\":\"{{percent}}\",\"value\":\"{{batterylevel}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":2930,"y":240,"wires":[["a79d657b.d79498"]]},{"id":"130d7cc9.841023","type":"api-current-state","z":"9f20b43d.4c5c78","name":"Battery charging?","server":"4bbca37b.1700ec","version":1,"outputs":2,"halt_if":"charging","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"{{state}}","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":2890,"y":380,"wires":[["5ad20ac.96d24f4"],["fb2484ba.c981a8"]]},{"id":"fe1e0ad4.6ca7b8","type":"api-current-state","z":"9f20b43d.4c5c78","name":"Get the batterylevel","server":"4bbca37b.1700ec","version":1,"outputs":1,"halt_if":"","halt_if_type":"num","halt_if_compare":"is","override_topic":false,"entity_id":"{{level}}","state_type":"str","state_location":"batterylevel","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":2430,"y":340,"wires":[["cbdfba21.c06818","369d1c4.cb515e4"]]},{"id":"9176519d.8853a","type":"api-current-state","z":"9f20b43d.4c5c78","name":"Get the batterylevel","server":"4bbca37b.1700ec","version":1,"outputs":1,"halt_if":"","halt_if_type":"num","halt_if_compare":"is","override_topic":false,"entity_id":"{{level}}","state_type":"str","state_location":"batterylevel","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":2830,"y":180,"wires":[["cbdfba21.c06818"]]},{"id":"4bbca37b.1700ec","type":"server","z":"","name":"Home Assistant","addon":true}]
In this part I have used variables for level which is sensor.“phone”_battery_level and state and so on.
You can trigger it with a inject node set on time interval.
That way you trigger it to turn on and if the battery level is below 20% it should enter the loop.
If not, or if the phone does not charge at this current time turn off the charger.
For reference, this is my complete flow: