Writing to global variables in Fibaro Home Automation 2

Hi

I would like to translate this working phyton script to set a global variable in the Fibaro Home Automation system:

bathroom1_line_crossing

url = ‘http://username:passwword@ipaddress:80/api/globalVariables/Cam102LineDet
payload = {“value”:“1”}
r = requests.put(url,json=payload)
print(“From post”)
print (r.status_code)

time.sleep(2)

payload = {“value”:“0”}
r = requests.put(url,json=payload)
print(“From post”)
print (r.status_code)

in the home assistant language in :

Configuration.yaml

script:
cam102_triggered:
platform: rest
resource:http://username:passwword@ipaddress:80/api/globalVariables/Cam102LineDet
method: POST
payload: ‘{ “Value” : “1” }’
cam102_not_triggered:
platform: rest
resource:http://username:passwword@ipaddress:80/api/globalVariables/Cam102LineDet
method: POST
payload: ‘{ “Value” : “0” }’

Automation.yaml

  • alias: Bathroom1_Cam102
    trigger:
    platform: state
    entity_id: binary_sensor.bathroom1_line_crossing
    from : ‘off’
    to: ‘on’
    action:
    service : script.turn_on
    entity_id : script.cam102_triggered
    platform :time
    delay: 00:01:00
    service : script.turn_on
    entity_id : script.cam102_not_triggered

I still seem to get errors

do I got the principles right ? syntax ?

Please see the big blue box at the top about formatting your posts. Wrap your code and YAML using </>.

Hi

Take 2 - with block quotes - hope I got it right

I would like to translate this working phyton script to set a global variable in the Fibaro Home Automation system:

<bathroom1_line_crossing
url = 'http://username:passwword@ipaddress:80/api/globalVariables/Cam102LineDet’
payload = {“value”:“1”}
r = requests.put(url,json=payload)
print(“From post”)
print (r.status_code)
time.sleep(2)
payload = {“value”:“0”}
r = requests.put(url,json=payload)
print(“From post”)
print (r.status_code)>

in the home assistant language in :

Configuration.yaml

<script:
cam102_triggered:
platform: rest
resource:http://username:passwword@ipaddress:80/api/globalVariables/Cam102LineDet
method: POST
payload: ‘{ “Value” : “1” }’
cam102_not_triggered:
platform: rest
resource:http://username:passwword@ipaddress:80/api/globalVariables/Cam102LineDet
method: POST
payload: ‘{ “Value” : “0” }’>

In Automation.yaml

<alias: Bathroom1_Cam102
trigger:
platform: state
entity_id: binary_sensor.bathroom1_line_crossing
from : 'off’
to: 'on’
action:
service : script.turn_on
entity_id : script.cam102_triggered
platform :time
delay: 00:01:00
service : script.turn_on
entity_id : script.cam102_not_triggered>

I still seem to get errors

do I got the principles right ? syntax ?
[/quote]

You need to post your original yaml, with all the formatting. It should look like one of these, not like a wall of text - see here for some more.

The key thing is - formatting is critical. Without it there’s no way to know if you’ve got the syntax right.

Oh, and do tell us what the errors are. Knowing those will help us help you.

Configuration file: updated

sensor:
- platform: rest
name : cam102
resource: http://ipaddres:80/api/globalVariables/Cam102LineDet
method: POST
payload: ‘{ “Value” : “9” }’
username: user
password: password
authentication: basic
headers:
User-Agent: Home Assistant
Content-Type: application/json

errors are now:

2017-09-16 20:49:18 ERROR (Thread-2) [homeassistant.util.yaml] mapping values are not allowed here
in “/home/homeassistant/.homeassistant/configuration.yaml”, line 58, column 12
2017-09-16 20:49:18 ERROR (MainThread) [homeassistant.bootstrap] Error loading /home/homeassistant/.homeassistant/configuration.yaml: mapping values are not allowed here
in “/home/homeassistant/.homeassistant/configuration.yaml”, line 58, column 12

You’re still not formatting correctly, so we can’t see what the problem might be. Please read the blue box at the top - wrap your YAML with </>.

Sorry got the quotes right now

Trying to write this working Python script into configuration.yaml

   url = 'http://username:passwword@ipaddress:80/api/globalVariables/Cam102LineDet’
   payload = {“value”:“1”}
   r = requests.put(url,json=payload)
   print(“From post”)
   print (r.status_code)
   time.sleep(2)
   payload = {“value”:“0”}
   r = requests.put(url,json=payload)
    print(“From post”)

Tried the first leg just to define a sensor in Configuration.yaml

sensor:
   - platform: rest
         name: cam102
         resource: http://ipaddres:80/api/globalVariables/Cam102LineDet
         method: POST
         payload: '{ “Value” : “1” }'
         username: user
         password: password
         authentication: basic
         headers:
            User-Agent: Home Assistant
            Content-Type: application/json

in the automations.yaml

    alias: Bathroom1_Cam102
      trigger:
      platform: state
      entity_id: binary_sensor.bathroom1_line_crossing
      from : 'off’
        to : 'on’
      action:
        service : sensor.turn_on
        entity_id : sensor.cam102
 

but got the following errors home-assistant.log

in “/home/homeassistant/.homeassistant/configuration.yaml”, line 58, column 12
2017-09-16 20:49:18 ERROR (MainThread) [homeassistant.bootstrap] Error loading /home/homeassistant/.homeassistant/configuration.yaml: mapping values are not allowed here
in “/home/homeassistant/.homeassistant/configuration.yaml”, line 58, column 12

The RESTFul documents show definition of payload. Perhaps I should try a “value_template”

or should just simply execute the working python script in an alternative method.
or try an define it as switch.

would appreciate a bit of help.

here is the error log with truncation:

2017-09-16 20:44:16 ERROR (Thread-2) [homeassistant.util.yaml] mapping values are not allowed here
in “/home/homeassistant/.homeassistant/configuration.yaml”, line 57, column 11
2017-09-16 20:44:16 ERROR (MainThread) [homeassistant.bootstrap] Error loading /home/homeassistant/.homeassistant/configuration.yaml: mapping values are not allowed here
in “/home/homeassistant/.homeassistant/configuration.yaml”, line 57, column 11

You’ve got too many spaces, each level should be two, not three. Yaml is very picky about you getting spaces in the right places, and not in the wrong places.

sensor:
  - platform: rest
    name: cam102

Is the correct indenting. You’ve also got a problem in that you’re using “smart” quotes:

     payload: '{ “Value” : “1” }'

Should be

     payload: '{ "Value" : "1" }'

The automation also has incorrect spacing, and smart quotes. It should be:

alias: Bathroom1_Cam102
  trigger:
    platform: state
    entity_id: binary_sensor.bathroom1_line_crossing
    from: 'off'
    to: 'on'
  action:
    service: sensor.turn_on
    entity_id: sensor.cam102

Also, there’s no service sensor.turn_on - you can’t turn sensors on.

Thank you very much. I will give it a go.