In future please format your pasted config correctly for the forum. Use the </>
button or do this: https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16
What does this return in Developer Tools β Template editor:
{{ state_attr('sensor.network_scanner', 'devices') }}