Help with config for new sensor

90 views
Skip to first unread message

Michelle Avery

unread,
Jul 8, 2015, 4:11:25 PM7/8/15
to home-assi...@googlegroups.com
I've written a new sensor to work with my efergy energy monitor, but I'm new to Home Assistant and to YAML configs in general , so I'm not quite sure how to write the config for one particular part (I'm a python beginner too for that matter, so I'm excited to have gotten this far!).  My config currently works like this:

sensor:
 
- platform: efergy
    app_token
: <token>
    utc_offset
: 300
    monitored_variables
:
     
- instant_readings
     
- budget
     
- daily_cost


This works fine, but I'd like to make it more flexible.  The API call for the cost currently takes a "period" parameter, which can be day, month, or year.  Currently, I have it hard coded to "day", but I'd like to be able to take this from the config, so that it would work something like this:

sensor:
 
- platform: efergy
    app_token
: <token>
    utc_offset
: 300
    monitored_variables
:
     
- instant_readings
     
- budget
     
- cost
        period
: day

That configuration, however, doesn't seem to be parsable, as it results in the following when I try to start up homeassistant:

Traceback (most recent call last):
  File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/src/home-assistant/homeassistant/__main__.py", line 154, in <module>
    main()
  File "/usr/src/home-assistant/homeassistant/__main__.py", line 137, in main
    hass = bootstrap.from_config_file(config_path)
  File "/usr/src/home-assistant/homeassistant/bootstrap.py", line 181, in from_config_file
    config_dict = config_util.load_config_file(config_path)
  File "/usr/src/home-assistant/homeassistant/config.py", line 112, in load_config_file
    return load_yaml_config_file(config_path)
  File "/usr/src/home-assistant/homeassistant/config.py", line 147, in load_yaml_config_file
    conf_dict = parse(config_path)
  File "/usr/src/home-assistant/homeassistant/config.py", line 132, in parse
    raise HomeAssistantError()
homeassistant.HomeAssistantError


Any pointers?

Paulus Schoutsen

unread,
Jul 9, 2015, 1:28:00 AM7/9/15
to home-assi...@googlegroups.com
It's not working because there is a syntax error in your YAML file: you are specifying a list but then all of a sudden use a dict/hash syntax. Notice how only period: day is a key/value pair while the other are list items.

You could convert that one entry to be a dictionary (like this) but then you will have to check in your parsing if the value in the list is a string or a dictionary. You might want to consider converting all entries to be a dictionary.

See the systemmonitor sensor source code for an example to use dictionaries inside the list.

--
You received this message because you are subscribed to the Google Groups "Home Assistant Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to home-assistant-...@googlegroups.com.
To post to this group, send email to home-assi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/home-assistant-dev/c0d2ffbd-cfed-419b-93d5-6eb676762ab7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
It's nice to be important but it's more important to be nice.

Michelle Avery

unread,
Jul 9, 2015, 10:52:46 AM7/9/15
to home-assi...@googlegroups.com
I see.  I was confused on the difference in the syntax.  Changing it to have all entries be a dictionary is exactly what I was looking for.  Thanks.
Reply all
Reply to author
Forward
0 new messages