Page 1 of 1

Writing a file with a value to /home/pi/Documents on Raspberry

Posted: Thursday 27 June 2019 14:17
by paul402
I have scripts working from switch triggers in /home/pi/domoticz/scripts/python.
The file value written allows a Python program to freeze certain garden window shutters. All well and good.
I would like a Dzvents script to directly write a value to a python file in /home/pi/Documents on a Raspberry so that another python script accessing that file (not in the Domoticz scripts directory) can work with the data.
I couldn't find any info about this. Does it mean that it is not possible?

Re: Writing a file with a value to /home/pi/Documents on Raspberry

Posted: Thursday 27 June 2019 16:17
by waaren
paul402 wrote: Thursday 27 June 2019 14:17 I would like a Dzvents script to directly write a value to a python file in /home/pi/Documents on a Raspberry so that another python script accessing that file (not in the Domoticz scripts directory) can work with the data.
Sure it is but this is not specific to domoticz or dzVents so you will find the information on how to do that in more generic Lua documentation. I cannot see in your post what kind of value you need and if you want to (re)create a file or insert a value in an existing file. The example below just create a file when it does not exist and append a text line including a variable (here a date/time).

Code: Select all

-- write value to file
return 
{
    on = { timer = { 'every minute' }},  -- just for the example

    logging = { level = domoticz.LOG_DEBUG, marker = 'value2File' },

    execute = function( dz )
        local out = '/home/pi/Documents/"Python file"'
        
       local function osCommand(cmd)
            local fileHandle     = assert(io.popen(cmd, 'r'))
            local commandOutput  = assert(fileHandle:read('*a'))
            local returnTable    = {fileHandle:close()}
            dz.log('\nCommand:       ' .. cmd ..
                   '\nReturnCode:    ' .. returnTable[3] ..
                   '\ncommandOutput: ' .. commandOutput, 
                   dz.log_debug)
            return commandOutput,returnTable[3]            -- rc[3] contains returnCode
        end
        
        osCommand ('echo dzVents was here at ' .. dz.time.rawDate .. ' ' .. dz.time.rawTime .. ' >> '  .. out .. '; chmod a+r ' .. out ) 
    end
}

Re: Writing a file with a value to /home/pi/Documents on Raspberry

Posted: Thursday 27 June 2019 16:43
by Egregius
The pass2php version :lol: :mrgreen:

Code: Select all

lg('Pass2PHP whas here at '.strftime("%F %T", TIME));
Sorry, can't help it. It's stronger than myself :oops:

Re: Writing a file with a value to /home/pi/Documents on Raspberry  [Solved]

Posted: Friday 28 June 2019 10:06
by paul402
A big thanks to both of you for a) putting me on the right track. It's so easy when you know how, and b) giving me a new avenue of php to explore!