Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

Voltage to Pressure QA - please help


Question

Posted

Hello everybody. I am a begginer in LUA programming. I tried to make a QA which reads a voltage value from a Fibaro implant (which measures the voltage on a pressure sensor), use a formula which calculates the pressure from the voltage, displays it on the same QA device and make it available to other devices for use.. The voltage is read, the pressure is correctly calculated, but it is not displayed on the QA device. It stays always zero...

This is the QA I've done, please help:

 

-- Fibaro HC3 Quick App to simulate a device based on voltage sensor 
 
-- Device ID of the voltage sensor
local voltageSensorId = 934
 
-- Device ID for the simulated pressure device
local simulatedPressureDeviceId = 918
 
-- Function to calculate pressure based on voltage
function calculatePressure(voltage)
    return 1.75*voltage - 1.87
end
 
-- Function to update the simulated pressure device
function updateSimulatedPressureDevice(voltage)
    local pressure = calculatePressure(voltage)
    hub.debug("Voltage: " .. voltage .. "V, Simulated Pressure: " .. pressure .. "atm")
    hub.call(simulatedPressureDeviceId, "setProperty""ui.label.value", pressure .. "atm")
end
 
-- Main loop to continuously read voltage and update the simulated device
while true do
    local voltage = hub.getValue(voltageSensorId, "value")
    updateSimulatedPressureDevice(voltage)
     
    hub.sleep(10000-- Sleep for 10 seconds
end

2 answers to this question

Recommended Posts

  • 0
Posted

@videovox

 

Your signature shows that you have an HC2 but you are talking about the Quick App for HC3. Please change your signature status to avoid incorrect answers to your questions.

 

Regarding your question about converting voltage to pressure, you do that in the configuration of your SmartImplant.
Then you don't need to do your own calculation and the device will be displayed correctly.
See my example where I convert voltage to cm on a level gauge.

 

Please login or register to see this link.

  • Like 1
  • 0
  • Inquirer
  • Posted

    Thanks a lot @RH_Dreambox for your answer. I updated my profile with HC3. I forgot to change it when I upgraded my system.

    I did not know the trick with setting limits for implant, it is a very useful setting that works well.

    3 hours ago, RH_Dreambox said:

    @videovox

     

    Your signature shows that you have an HC2 but you are talking about the Quick App for HC3. Please change your signature status to avoid incorrect answers to your questions.

     

    Regarding your question about converting voltage to pressure, you do that in the configuration of your SmartImplant.
    Then you don't need to do your own calculation and the device will be displayed correctly.
    See my example where I convert voltage to cm on a level gauge.

     

    Please login or register to see this link.

     

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...