Help with ListValue and validation


I am new to OpenWrt and lua and couldn't find much information online. I added a new tab to my OpenWrt installation and need some help with the user input / ListValue object.
I have OpenWrt 22.03.3 installed on my device.
The values of the ListValue will be sent to a microcontroller via serial interface by a python script.

I either need to check the values before it gets sent to assure the combination of both input values is allowed.
Or I can send the values to the MCU and the MCU sends a "OK" or "Error" reply. In this case I would need to add a message somehow to show if the values were ok or not.

The simplified code for the tab is

m = Map("test_file", translate("Test settings"), translate("This is just a test."))
m : chain ( "luci" )

s1=m:section ( TypedSection ,  "test_settings" ,  translate ( "Test ABC" ) )
s1.anonymous =  true
s1.addremove =  false

ov1=s1:option(ListValue, "ov1", translate("List Value 1 "))
ov1:value("20", "20")
ov1:value("21", "21")
ov1:value("22", "22")
ov1:value("23", "23")
ov1:value("24", "24")

ov2=s1:option(ListValue, "ov2", translate("List Value 2"))
ov2:value("0", "0")
ov2:value("1", "1")
ov2:value("2", "2")
ov2:value("3", "3")
ov2:value("4", "4")

btn_send = s1:option(Button, "_btn1", translate("Test 123"))
btn_send.title = translate("Set")
btn_send.inputtitle=translate("  SET  ")

function btn_send.write(self, section)
	cnt = m:formvalue(ov1)
	cmd = "python3 / " .. tostring(cnt)  .. "\n\r"
	return m

m.on_after_apply = function(self)	
	--cmd = "python3 / " .. tostring(cnt)  .. "\n\r"

I tried the validate function, not really sure how it works or how the syntax should be.

I could also use the button to send the values to the MCU and add a message to the tab.lua code before the page gets reloaded.
But I don't know how to get the ov1 and ov2 values into the btn_send.write function. When I press the button the python script sends "nil" as cnt.

Please can someone help me or point me in the right direction, thank you.

I solved the problem and managed to call a python script with the button and the values as arguments.

function btn_send.write(self, section)
	local ov1_value = ov1:formvalue(section)
	local ov2_value = ov2:formvalue(section)
	local cmd = "python3 /maelstrom/ " .. ov1_value .. " " .. ov2_value