I have now found the solution and just wanted to share:
To turn ON a switch device:
local switch = “switch.tv_fonster” – Name of the light dimmer in Home Assistant
local thisdevice = fibaro:getSelfId()
local ip = fibaro:getValue(thisdevice, ‘IPAddress’)
local port = fibaro:getValue(thisdevice, ‘TCPPort’)
local httpSession = Net.FHttp(ip, port);
jsonTable = { entity_id = switch }
jsonString = json.encode(jsonTable)
response, status, errorCode = httpSession:POST("/api/services/switch/turn_on", jsonString)
To turn On a dimmer device:
local light = “light.tv_fonster_dim” – Name of the light dimmer in Home Assistant
local thisdevice = fibaro:getSelfId()
local ip = fibaro:getValue(thisdevice, ‘IPAddress’)
local port = fibaro:getValue(thisdevice, ‘TCPPort’)
local httpSession = Net.FHttp(ip, port);
local sliderValue = fibaro:getValue(thisdevice, “ui.Slider1.value”) – Get Fibaro Slider Value
if tonumber(sliderValue) <= 5
then
jsonTable = { entity_id = light, brightness = “100” }
elseif tonumber(sliderValue) <= 20
then
jsonTable = { entity_id = light, brightness = math.floor((sliderValue*2.55)+0.5) }
else
jsonTable = { entity_id = light, brightness = “100” }
end
jsonString = json.encode(jsonTable)
response, status, errorCode = httpSession:POST("/api/services/light/turn_on", jsonString)
If the dimmer is set to high or low it will revert back to 100 of the max 255.
But in Fibaro the max value is 100 so that is why I need to multiply with 2.55